100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Bash

Navigating the Filesystem (cd, pwd, ls)

Practical mastery of moving around the Linux directory tree using cd, pwd, and ls, including absolute vs relative paths and useful ls flags for everyday work.

Navigating & Managing FilesBeginner8 min readJul 9, 2026
Analogies

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.

bash
# 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 | less

The 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 cdls ~/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.

  • pwd prints your current working directory; cd changes it; ls lists directory contents.
  • Absolute paths start with '/' and are unambiguous; relative paths are resolved against the current directory.
  • . means current directory, .. means parent directory, and cd - toggles back to the previous directory.
  • cd with no argument, cd ~, and cd $HOME all take you to your home directory.
  • ls -lah is 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

Was this page helpful?

Topics covered

#Bash#LinuxShellScriptingStudyNotes#DevOps#NavigatingTheFilesystemCdPwdLs#Navigating#Filesystem#Pwd#Absolute#StudyNotes#SkillVeris