This chapter covers the essential commands for moving around and understanding your location within the Linux file system hierarchy.
1. Printing the Working Directory (pwd)
The pwd (Print Working Directory) command tells you exactly where you are in the file system hierarchy. It always outputs the absolute path starting from the root directory (/).
Execution
pwd
2. Changing Directories (cd)
The cd (Change Directory) command is the most frequently used command for moving between locations in the file system. It requires an argument specifying the destination path.
Essential cd Usage
| Target | Command | Result |
| Home Directory | cd or cd ~ | Moves you to your user’s home directory (e.g., /home/username). |
| Root Directory | cd / | Moves you to the top-most level of the file system. |
| Parent Directory | cd .. | Moves you one level up (the parent of the current directory). |
| Previous Directory | cd - | Toggles back to the last directory you were in. |
Execution Examples
To move into a directory named Documents relative to your current location:
cd Documents
To move to a directory named bin which is two levels up from your current location:
cd ../../bin
To move directly to the home directory of a user named ‘alex’ (using an absolute path):
cd /home/alex
3. The Linux File System Hierarchy
The Linux file system is organized as a single inverted tree, starting at the root (/).
Understanding the primary top-level directories is helpful:
/(Root): The base of the file system./home: Contains the personal directories for all non-root users (e.g.,/home/alex)./binand/usr/bin: Contains essential binary executable programs (commands)./etc: Contains global system configuration files./var: Contains variable data, such as logs, mail, and web server content.
4. Tab Completion
A key efficiency feature in the shell is tab completion. When typing a command, file name, or directory name, pressing the Tab key will automatically complete the name if it is unique. If multiple options match, pressing Tab twice will list all possible completions.
