Navigating the Filesystem (cd, pwd, ls)
Three commands form the foundation of everyday Linux navigation: pwd (print working directory) tells you where you currently are, cd (change directory) moves you somewhere else, and ls (list) shows what's in a directory. Simple as they sound, fluency with their options and with path syntax is what separates someone who fumbles through the filesystem from someone who moves through it efficiently, especially over SSH sessions with no GUI file browser available.
Cricket analogy: pwd, cd, and ls are like knowing your current field position, moving to a new position on the captain's call, and reading who's fielding where — basics that separate a player who fumbles around the ground from one who moves with purpose, especially without a coach pointing things out.
Absolute vs. Relative Paths
An absolute path always starts from the root, /, and fully specifies a location regardless of your current directory — e.g. /var/log/syslog. A relative path is interpreted relative to your current working directory — e.g. running cd logs from /var moves you to /var/logs if it exists. Two special relative components are used constantly: . refers to the current directory, and .. refers to the parent directory. cd .. moves up one level, cd ../.. moves up two levels, and cd - is a convenient shortcut that switches back to whatever directory you were in before your last cd. cd with no arguments always returns you to your home directory, equivalent to cd ~ or cd $HOME.
Cricket analogy: An absolute path is like naming the exact ground, city, and stand — "Eden Gardens, north stand" — regardless of where you currently are; a relative path is like saying "two gates down" from wherever you're standing now; cd - is like a captain switching back to the previous batting order instantly, and cd with no args always sends you back to the home ground.
Listing Contents with ls
Plain ls lists visible entries in the current directory, but its flags unlock far more useful views: -l gives a 'long' listing with permissions, owner, group, size, and modification time; -a shows hidden files (those starting with ., including . and .. themselves); -h makes -l's file sizes human-readable (e.g. 4.0K instead of 4096); -t sorts by modification time (newest first); and -R recurses into subdirectories. These are commonly combined, e.g. ls -lah is one of the most frequently typed command sequences in Linux administration.
Cricket analogy: Plain ls is glancing at just the visible scoreboard; -l adds full details like each batsman's strike rate and balls faced; -a reveals hidden reserve players not shown on the main sheet; -h converts raw run totals into readable milestones like "a century" instead of "104"; -t sorts recent form by most recent match first; -R drills into every sub-format; and ls -lah combined is the full detailed, readable, complete-roster view a scout checks first.
# Where am I?
pwd # /home/alice/projects
# Move around
cd /var/log # absolute path
cd ../lib # relative path: up one, then into lib
cd ~ # go to home directory
cd - # jump back to the previous directory
cd # no argument also goes home
# List contents
ls # basic listing
ls -lah # long, all (incl. hidden), human-readable sizes
ls -lt # long listing sorted by modification time, newest first
ls -R /etc/ssh # recursive listing
# Combine navigation with listing in one line
cd /etc && ls -la | lessThe tilde ~ is expanded by the shell itself before the command even runs, not by cd. ~ expands to $HOME, and ~username expands to that user's home directory (e.g. ~bob → /home/bob). This expansion happens for any command, not just cd — ls ~/Documents and cp file.txt ~/backup/ both work the same way.
Beware of paths containing spaces or special characters — cd My Documents will fail because the shell splits it into two arguments. Quote the path (cd "My Documents") or escape the space (cd My\ Documents) instead. This same word-splitting issue is one of the most common sources of bugs in shell scripts, not just interactive navigation.
pwdprints your current working directory;cdchanges it;lslists directory contents.- Absolute paths start with '/' and are unambiguous; relative paths are resolved against the current directory.
.means current directory,..means parent directory, andcd -toggles back to the previous directory.cdwith no argument,cd ~, andcd $HOMEall take you to your home directory.ls -lahis the most common combination: long format, all files including hidden ones, human-readable sizes.- Unquoted paths with spaces are split by the shell into multiple arguments — always quote or escape them.
Practice what you learned
1. What does `cd -` do?
2. Which ls flag combination shows hidden files with human-readable sizes in long format?
3. What is the key difference between an absolute path and a relative path?
4. What does running `cd` with no arguments do?
5. Why does `cd My Documents` fail if the directory is literally named 'My Documents'?
Was this page helpful?
You May Also Like
The Linux Filesystem Hierarchy
A tour of the standard Linux directory tree defined by the Filesystem Hierarchy Standard (FHS) — what lives under /etc, /var, /usr, /home, and more, and why the layout matters.
Creating and Removing Files and Directories
How to create empty files and directory trees with touch and mkdir, and safely remove them with rm and rmdir, including the dangers of recursive deletion.
Copying, Moving, and Renaming
How cp and mv handle copying, moving, and renaming files and directories, including recursive copies, preserving attributes, and safe overwrite behavior.
Finding Files with find and locate
Master the two main Linux file-search tools: the real-time, highly flexible find command and the fast, index-based locate command, including when to use each.
Related Reading
Related Study Notes in DevOps
Browse all study notesNginx Study Notes
DevOps · 30 topics
DevOpsAnsible Study Notes
DevOps · 30 topics
DevOpsAdvanced Kubernetes Study Notes
Kubernetes · 30 topics
DevOpsAdvanced Bash Scripting Study Notes
Bash · 30 topics
DevOpsApache Kafka Study Notes
Kafka · 30 topics
DevOpsDocker & Kubernetes Study Notes
YAML · 40 topics