Where Am I? The pwd Command
When you open a terminal, you are always "standing" inside a directory on your file system.
Before you start moving around, it helps to know exactly where you are. That is what
pwd (print working directory) does.
pwd
The output will look something like:
/home/john
This tells you the full, absolute path of the directory you are currently in. On Linux,
every user has a home directory located at /home/username. When you first
open a terminal, this is where you start.
An absolute path starts from the root of the file system (/) and
describes the complete location, like /home/john/Documents. A relative
path describes a location relative to where you currently are, like Documents
(no leading slash). Both are valid ways to refer to files and directories.
Moving Around with cd
The cd (change directory) command is how you move from one directory to another.
It is the most frequently used navigation command and the foundation of terminal workflow.
Basic Usage
To move into a directory, type cd followed by the directory name or path:
# Move into the Documents folder
cd Documents
# Verify you moved
pwd
/home/john/Documents
Going Up with ..
Two dots (..) represent the parent directory -- the directory one level above
your current location. You can chain them together to go up multiple levels.
# Go up one level
cd ..
# Go up two levels
cd ../..
# Go up one level and into a sibling directory
cd ../Downloads
Handy cd Shortcuts
cd with no arguments.
# Jump home from anywhere
cd ~
# Or simply
cd
# Toggle between two directories
cd /var/log
cd /etc/nginx
cd -
# You are now back in /var/log
Listing Files with ls
Once you have navigated to a directory, you need to see what is inside it. The ls
command lists the contents of a directory.
Basic ls
ls
This shows the names of files and folders in your current directory. However, it hides files that start with a dot (hidden files) and does not show much detail.
Useful ls Flags
# List everything with details
ls -la
total 32
drwxr-xr-x 5 john john 4096 Mar 1 10:30 .
drwxr-xr-x 3 root root 4096 Feb 15 08:00 ..
-rw------- 1 john john 1200 Mar 1 09:15 .bash_history
-rw-r--r-- 1 john john 220 Feb 15 08:00 .bashrc
drwxr-xr-x 2 john john 4096 Feb 20 14:00 Documents
drwxr-xr-x 2 john john 4096 Feb 22 11:30 Downloads
-rw-r--r-- 1 john john 675 Feb 15 08:00 .profile
You can also list the contents of a specific directory without navigating into it:
# List contents of /etc without moving there
ls -l /etc
Tab Completion for Faster Navigation
One of the most powerful features of the Linux terminal is tab completion. Instead of typing out long directory or file names in full, you can type the first few characters and press Tab.
cd Doc
cd Documents/
Get into the habit of using Tab after every few characters. It is faster than typing full names, and if nothing completes, it tells you the path does not exist -- catching mistakes before you run the command.
Understanding the Linux Directory Tree
Linux organizes everything into a single directory tree starting at the root (/).
Unlike Windows which uses drive letters (C:\, D:\), Linux mounts everything under this
one tree. Here are the most important directories you will encounter:
/var/log) and web files (/var/www).
/usr/bin.
Directories like /etc, /usr, and /var contain
files that your system needs to run. Browse them freely with ls, but do not
modify anything there unless you know what you are doing.
Summary
In this tutorial, you learned the three core navigation commands:
- pwd -- Print your current working directory
- cd -- Change to a different directory (with shortcuts like
~,.., and-) - ls -- List directory contents (with flags like
-laand-lh) - The difference between absolute and relative paths
- How to use Tab completion to navigate faster
- The basic layout of the Linux directory tree
You can now move around the Linux file system with confidence. In the next tutorial, you will learn how to create, copy, move, and delete files and directories.