Linux Filesystem Navigation
1. Introduction
Navigating the filesystem is fundamental to using any Linux environment. In this guide, we explore some of the most common commands for moving around directories and listing/managing their contents.
2. Common Commands
Below are five essential commands for Linux filesystem navigation:
pwd
, cd
, ls
, mkdir
, and
rmdir
. Each command’s usage and flags are highlighted below.
2a. pwd
pwd
stands for “Print Working Directory.” It displays
the absolute path of the current directory you’re in.
Command / Flag | Description |
---|---|
pwd |
Shows the absolute path of your current directory. |
pwd -L |
Prints the logical path, preserving symbolic links. |
pwd -P |
Prints the physical path, resolving all symbolic links. |
2b. cd
cd
(change directory) lets you move from your current
directory to another. When used without arguments, it returns you to
your home directory.
Usage / Flag | Description |
---|---|
cd [directory] |
Moves you into the specified [directory] . |
cd |
No arguments: returns you to your home directory (~). |
cd - |
Switches back to your previously visited directory. |
cd .. |
Moves up one level to the parent directory. |
2c. ls
ls
lists the contents of a directory. Various flags
alter the scope (e.g., hidden files) or how details are displayed.
Flag | Description |
---|---|
-a |
Shows all files, including those starting with . . |
-l |
Long format; displays permissions, owner, size, modification date. |
-h |
Used with -l ; shows sizes in human-readable form (KB, MB, etc.). |
-la |
Combines -l and -a , listing hidden files in long format. |
2d. mkdir
mkdir
(make directory) creates a new folder. The -p
flag allows nested directories to be created as needed.
Flag / Usage | Description |
---|---|
mkdir [name] |
Creates a directory named [name] in the current path. |
mkdir -p [path] |
Creates parent directories as needed (e.g., /path/to/dir ). |
2e. rmdir
rmdir
(remove directory) deletes an empty directory.
If the directory has contents, you’ll need rm -r
or another command.
Flag / Usage | Description |
---|---|
rmdir [dir] |
Removes the empty directory [dir] . |
rmdir -p [path] |
Removes parent directories if each becomes empty.
E.g., rmdir -p /path/to/dir removes dir ,
then to , if they are empty.
|
3. Conclusion
With pwd
, cd
, ls
, mkdir
,
and rmdir
in your toolkit, you can navigate and manage
directories comfortably in most Linux environments. Learning these basics
paves the way for more advanced operations on a Unix-like system.