File System Paths.
File system paths are essential for navigating and managing files in Linux. They can be categorized into two main types: absolute paths and relative paths.
Absolute Path
- Starts from the root
/directory. - Describes the full location of a file or folder.
Example:
cd /home/user/DocumentsThis takes you directly to the Documents folder of user.
Relative Path
- Relative to the current working directory.
- Doesn’t start with
/.
Example:
cd Documents/ReportsThis navigates to Documents/Reports assuming you’re currently in /home/user.
Special Path Symbols
| Symbol | Meaning |
|---|---|
. | Current directory |
.. | Parent directory |
~ | Home directory of the current user |
- | Previous working directory |
cdCommand – Change Directory
Syntax:
cd [directory]If no argument is given, it goes to the user’s home directory.
Chain with relative path
cd /home/user/Documents
cd ../Pictures
pwdOutput:
/home/user/PicturesTip: Tab Completion
When using cd, press Tab to auto-complete directory names:
cd /var/lo<Tab>It auto-completes to:
cd /var/logCommon Errors
Directory doesn’t exist
cd /nonexistent/pathOutput:
bash: cd: /nonexistent/path: No such file or directoryPermission denied
cd /rootOutput (as non-root user):
bash: cd: /root: Permission deniedRelated Commands
pwd: Print working directory.ls: List contents of a directory.ls -l: Long listing with permissions and timestamps.
Last updated on