Now that we’ve covered Linux filesystem layout, we have a clear idea where to navigate in Linux, In this post we’ll cover the following commands
pwdmkdirlscd
Understanding your Location with pwd
The pwd command shows your current location in the Linux filesystem
Usage
pwdExample Output
/home/polyIn this example, I’m currently in my user home directory. The command is simple yet invaluable, especially when you’re deep in the directory tree and need to confirm your location
Creating a directory with mkdir
The mkdir command basically creates a new directory in your current location, think of it as creating a new folder on windows
Usage
mkdir homeworkmkdir does not give you an output. In this example, it simply creates the directory “homework”. We can store anything in this directory, your homework files or anything else.
Listing directory content with ls
The ls command displays files and directories in your current location. It’s highly versatile with numerous options
Usage
lsExample Output
homeworkRemember, the homework directory we created earlier? Yep, ls will display that such a directory exists in our current location.
There are also other useful options that ls provides for example:
ls -l: Long format with detailed information (permissions, owner, size, date)ls -a: Show all files, including hidden ones (those starting with.)ls -h- Human-readable file sizes (KB, MB, GB)ls -t- Sort by modification time, newest firstls -R- Recursive listing of subdirectories
You can also combine options. For instance:
ls -lahThis shows all files (including hidden ones) in a detailed, human-readable format, a very common and practical command in daily use.
Changing Directories with cd
The cd (Change Directory) command is how you navigate through the filesystem. It’s one of the most frequently used commands you’ll encounter.
Basic usage:
cd homeworkThis command moves you into the homework directory we created earlier.
Common patterns:
cd ~or justcd: Go to your home directorycd ..: Move up one directory levelcd ../..: Move up two directory levelscd -: Return to the previous directorycd /: Go to the root directory
Example workflow:
pwd # Shows: /home/poly
cd homework # Navigate to homework directory
pwd # Shows: /home/poly/homework
cd .. # Go back to parent directory
pwd # Shows: /home/polyPro tip: Use Tab completion to speed up navigation. Type the first few letters of a directory name and press Tab to auto-complete.
Conclusion
Now that we’ve covered the absolute basics of creating directories, changing directories and listing directories in Linux, you can experiment on your own and navigate through your Linux filesystem with confidence.
| Command | Purpose | Example Usage |
|---|---|---|
pwd | Show current directory | pwd |
mkdir | Create directory | mkdir homework |
ls | List files | ls -lah |
cd | Change directory | cd homework |
In the next guide, we’ll cover about basic text editors like nano and vi. We’ll also be introducing more shell commands like cat and cp to complement what we’ve learnt here.
