Navigating the Filesystem: pwd, ls, cd

beginner
10 min

Navigating the Filesystem: pwd, ls, cd

Everything in Linux lives in a single directory tree that starts at the root, written as /. There are no drive letters like C:—disks, USB sticks and even devices appear as folders inside that one tree. In this lesson you will learn the three commands you will type more than any others: pwd, ls and cd.

The Linux Directory Tree

A few directories are worth recognizing early:

  • / – the root of everything
  • /home – personal folders for each user (yours is /home/yourname)
  • /etc – system configuration files
  • /bin and /usr/bin – the programs (commands) themselves
  • /var – logs and variable data, e.g. /var/log
  • /tmp – temporary files, cleared on reboot

Your home directory is where you keep your own files. The shell abbreviates it as ~ (tilde).

pwd: Where Am I?

pwd stands for print working directory. It shows the folder your shell is currently "standing in":

bash
pwd # /home/sam

Every command you run operates relative to this location unless you say otherwise, so knowing where you are is step one of everything.

ls: What Is Here?

ls lists the contents of a directory. On its own it lists the current directory; give it a path to look elsewhere:

bash
ls # list current directory ls /etc # list a specific directory ls -l # long format: permissions, owner, size, date ls -a # include hidden files (names starting with .) ls -lh # long format with human-readable sizes (4.0K, 2.3M) ls -lt # sort by modification time, newest first

Hidden files start with a dot, like .bashrc. They are not secret—just tucked away so everyday listings stay clean. The -l output looks like this:

bash
-rw-r--r-- 1 sam sam 4096 Jul 20 10:30 notes.txt drwxr-xr-x 2 sam sam 4096 Jul 19 09:12 projects

A leading d means directory; a leading - means regular file. We decode the permission letters fully in lesson 5.

cd: Moving Around

cd (change directory) moves your shell to a new location:

bash
cd /var/log # go to an absolute path cd projects # go into a subfolder of the current directory cd .. # go up one level to the parent cd ../.. # up two levels cd ~ # jump home from anywhere cd # same as cd ~ cd - # jump back to the previous directory

Absolute vs Relative Paths

An absolute path starts with / and works from anywhere: /home/sam/projects/site. A relative path starts from where you are now: if you are in /home/sam, then projects/site reaches the same place. Two special names exist in every directory: . means "this directory" and .. means "the parent directory".

bash
cd /home/sam/projects # absolute cd ../downloads # relative: sibling folder of the current one

Tab Completion: Type Less, Err Less

Press Tab while typing a path and the shell completes it for you; press Tab twice to see all options. This is not a luxury—professionals rely on it to avoid typos:

bash
cd /var/lo<Tab> # completes to /var/log/ ls ~/Doc<Tab> # completes to ~/Documents/

Also try the Up arrow to recall previous commands, and clear (or Ctrl+L) to clean your screen.

Practice Session

bash
cd ~ pwd ls -la cd /etc ls | head cd - pwd

Run these in order and predict each output before pressing Enter—that habit turns commands into knowledge.

Key Takeaways

  • Linux has one directory tree rooted at /; your files live in ~ (your home).
  • pwd shows where you are, ls shows what is there, cd moves you.
  • .. is the parent directory, . is the current one, cd - returns to the previous location.
  • Absolute paths start with /; relative paths start from your current directory.
  • Tab completion prevents typos and doubles your speed.

Next lesson: Working with Files: touch, cp, mv, mkdir — start creating, copying and organizing files.

Navigating the Filesystem: pwd, ls, cd - Linux & Command Line | CodeYourCraft | CodeYourCraft