Linux, as a Unix-based operating system, has a different file system structure compared to Windows. Understanding how to navigate and manage files in Linux is essential for users. This article explores the fundamental commands pwd, cd, and ls, explaining how they work.
Linux File System Hierarchical Structure
Linux uses a hierarchical directory structure to store and manage files. Unlike Windows, where each storage device has a separate file system, Linux has a single file system tree where all storage devices are mounted at various points.
pwd Command – Displaying the Working Directory
Every user has a working directory upon logging into the system. To display the current location in the file system, use the pwd command:
pwd /home/user
This command prints the full path of the current working directory.
ls Command – Listing Directory Contents
The ls command lists files and folders inside the current working directory:
ls Desktop Documents Downloads Music
The ls command can also be used to list contents of any other directory.
cd Command – Changing the Working Directory
To navigate through the file system, use the cd command. Pathnames can be specified in two ways:
Absolute Path: Starts from the root (/) and follows the hierarchy to the destination.
Relative Path: Starts from the current directory and uses special symbols.
Example of changing the directory to /usr/bin:
cd /usr/bin pwd /usr/bin
Relative vs Absolute Paths
Navigating directories in Linux can be done using absolute or relative paths:
Absolute path starts from the root (/).
Relative path starts from the current working directory using special symbols:
Two important symbols used in relative paths:
. refers to the current directory.
.. refers to the parent directory (one level up).
Example of moving from /usr/bin to /usr using both methods:
cd /usr # Absolute Path cd .. # Relative Path
Both commands achieve the same result, but the relative path requires less typing.
Likewise, you can move from /usr to /usr/bin in two ways:
cd /usr/bin # Absolute Path cd ./bin # Relative Path
The ./ symbol can usually be omitted, making cd bin equivalent to cd ./bin.
Important Facts About Filenames in Linux
Linux follows specific rules for filenames:
Hidden files start with a period (.) and are only listed using ls -a.
Case sensitivity: File1 and file1 are different files.
Avoid spaces in filenames—use _ (underscore) instead.
No file extensions: Unlike Windows, Linux doesn’t rely on extensions to determine file types.
Useful cd Shortcuts
Some useful shortcuts for quick navigation in Linux:
Shortcut Action
cd Changes to the user's home directory
cd - Switches to the previous working directory
cd ~username Moves to the home directory of username
Conclusion
This guide explained how Linux organizes its directories and how users can navigate the system using absolute and relative paths, filename conventions, and essential shortcuts. Mastering pwd, ls, and cd enhances file system navigation efficiency.