Close-up of a computer monitor displaying cyber security data and code, indicative of system hacking or programming.

Linux cd, ls & pwd: Directory Navigation Commands You’ll Use Every Day

The three essential Linux commands for navigating directories are pwd (print working directory: shows where you are), ls (list: shows what is in a directory) and cd (change directory: moves you somewhere else). Run pwd to get your bearings, ls -la to see everything in the current directory including hidden files, and cd /path to move. cd .. goes up one level, cd - goes back to the previous directory and cd on its own takes you home.

That is the whole answer in one paragraph. The rest of this guide covers the flags you will actually use, what the output means, and the error messages you will hit (with the fix for each), checked against the GNU coreutils and Bash manuals for Ubuntu 24.04 LTS.

Command What it does Most useful form
pwd Prints the full path of the directory you are in pwd (or pwd -P to resolve symlinks)
ls Lists files and directories ls -la (long format, hidden files included)
cd Changes the current directory cd /var/log, cd .., cd -, cd

Terminal showing pwd, ls -la and directory navigation with cd
Real command output from a test machine, not a mock-up.

Navigation commands are muscle memory for anyone who works in infrastructure. I probably type ls -la and cd hundreds of times a day without thinking about it. These are the foundations that every other Linux skill builds on.

pwd: where am I?

pwd stands for print working directory. It prints the absolute path of the directory your shell is currently in:

$ pwd
/home/alex/projects

Run it before anything destructive. rm -r * in the wrong directory is how people lose an afternoon, and pwd costs nothing.

pwd and symbolic links: -L vs -P

If you reached a directory through a symlink, pwd can give two different answers:

$ cd /home/alex/link-to-data     # link-to-data is a symlink to /srv/data
$ pwd
/home/alex/link-to-data
$ pwd -P
/srv/data

-L (logical) shows the path you typed, symlinks included. -P (physical) resolves every symlink to the real directory. In Bash, the built-in pwd uses -L by default. The standalone /usr/bin/pwd from GNU coreutils defaults to -P unless POSIXLY_CORRECT is set, which is why the coreutils manual warns that a bare pwd can behave differently in different contexts. When a script needs the real path, use pwd -P.

ls: what is here?

ls lists the contents of a directory: the current one if you give no argument, or any path you name.

# Current directory
ls

# Another directory, without going there
ls /etc/nginx

# Long format: permissions, owner, size, date
ls -l

# Include hidden files (names starting with a dot)
ls -la

# Human-readable sizes (K, M, G)
ls -lh

# Newest first
ls -lt

# Oldest first, so the newest ends up at the bottom next to your prompt
ls -ltr

# Largest first
ls -lS

# The directory itself, not its contents
ls -ld /var/log

# Every subdirectory, recursively
ls -R

Reading ls -l output

Example output of ls -la in a home directory (your names, sizes and dates will differ):

$ ls -la
total 32
drwxr-x--- 4 alex alex 4096 Oct 31 09:12 .
drwxr-xr-x 3 root root 4096 Sep  2 14:20 ..
-rw------- 1 alex alex 1204 Oct 31 09:10 .bash_history
-rw-r--r-- 1 alex alex  220 Sep  2 14:20 .bash_logout
-rw-r--r-- 1 alex alex 3771 Sep  2 14:20 .bashrc
drwx------ 2 alex alex 4096 Sep  2 14:31 .ssh
drwxrwxr-x 3 alex alex 4096 Oct 30 17:45 projects

Left to right on each line: file type and permissions (d at the start means a directory, - a regular file, l a symlink), the link count, the owner, the group, the size in bytes, the last-modified time, and the name. . is the current directory and .. is its parent. Use ls -lA if you want hidden files without those two entries.

Flag Meaning When to use it
-l Long format Almost always
-a Show hidden files, including . and .. Looking for dotfiles and config
-A Show hidden files, omit . and .. Cleaner version of -a
-h Human-readable sizes With -l, whenever size matters
-t Sort by modification time, newest first Finding what just changed
-r Reverse the sort order -ltr puts the newest file last
-S Sort by size, largest first Finding what is eating space
-d List the directory itself, not its contents Checking a directory’s own permissions
-F Append / to directories, @ to symlinks, * to executables Telling types apart without colour
-R Recurse into subdirectories Small trees only; use find for big ones

Ubuntu’s default ~/.bashrc already defines three shortcuts: ll is ls -alF, la is ls -A and l is ls -CF. If ll works on one machine and not another, that is why. The full flag list is in the GNU coreutils ls documentation or man ls.

One version note: Ubuntu 24.04 LTS uses GNU coreutils 9.4. Ubuntu 25.10 switched ls and friends to uutils coreutils, a Rust rewrite. The flags in this guide work the same on both.

cd: go there

# Absolute path
cd /var/log

# Home directory (all three are equivalent)
cd
cd ~
cd $HOME

# Up one level, up two levels
cd ..
cd ../..

# Back to the previous directory (prints where you landed)
cd -

# Another user's home directory
cd ~alex

cd - switches between your current and previous directory, and prints the path it switched to. It is the fastest way to bounce between a config directory and a log directory while troubleshooting. Under the hood it uses the $OLDPWD variable, as described in the Bash manual’s entry for cd.

Directory names with spaces

The shell splits arguments on spaces, so cd My Documents fails with bash: cd: too many arguments. Quote the name or escape the space:

cd "My Documents"
cd My\ Documents

Tab completion adds the backslash for you, which is one more reason to use it.

cd is a shell builtin

There is no /usr/bin/cd program. cd is built into the shell because it has to change the shell’s own working directory, which a separate program cannot do. You can confirm it:

$ type cd
cd is a shell builtin

This matters in one common situation, covered in the troubleshooting section: sudo cd does not work.

Absolute and relative paths

An absolute path starts with / and works from anywhere. A relative path starts from wherever you are now.

# Absolute: the same result from any directory
cd /var/log/nginx

# Relative: depends on where you are
cd ../logs
cd ./scripts
Symbol Meaning Example
/ Root of the filesystem cd /
~ Your home directory cd ~/scripts
. Current directory ./script.sh
.. Parent directory cd ..
- Previous directory (with cd only) cd -

Tab completion

Press Tab to complete a path. Press it twice when there is more than one match to see the options:

# Type: cd /var/lo[TAB]
# Becomes: cd /var/log/

# Several matches? Tab twice lists them
cd /var/[TAB][TAB]

If you are typing full paths by hand, you are working too hard and inviting typos.

Practitioner tip: Get into the habit of using tab completion early. It’s faster and prevents typos in paths. On a production server, a typo in the wrong directory can have consequences.

The Linux filesystem: where things live

Navigation is easier when you know the destinations. These are the directories you will visit most on Ubuntu or any other mainstream distribution:

Directory Contains You’ll go here for
/ Root of the filesystem Everything starts here
/home User home directories User files, SSH keys
/root The root user’s home Root’s own config (needs sudo)
/etc System and application configuration Editing config files
/var/log Log files Troubleshooting
/var/www Web content (by convention) Web server files
/tmp Temporary files, cleared on reboot Scratch space
/opt Optional add-on software Third-party apps
/usr/bin Most user commands Finding executables
/usr/local Locally installed software Things you compiled or installed by hand
  • Interview question: “Where would you look for nginx configuration?” Answer: /etc/nginx/, with site configs in /etc/nginx/sites-available/ and /etc/nginx/sites-enabled/ on Debian and Ubuntu.

Finding things

find: search by name, age or size

# By name
find /var/log -name "*.log"

# Modified in the last 24 hours
find /var/log -mtime -1

# Larger than 100 MB (2>/dev/null hides permission errors)
find / -size +100M 2>/dev/null

# Directories only
find /var -type d -name "log*"

# Files only
find /home -type f -name "*.conf"

locate: fast filename search

# Not installed by default on Ubuntu Server
sudo apt install plocate

# Search (the database is refreshed daily; force it with sudo updatedb)
locate nginx.conf

# Case-insensitive
locate -i readme

locate searches a pre-built index, so it is near-instant but can miss files created since the last update. find walks the disk in real time.

which and whereis: find a command

$ which python3
/usr/bin/python3

# Binary, library and man page locations (example output, paths vary)
$ whereis python3
python3: /usr/bin/python3 /usr/lib/python3 /usr/share/man/man1/python3.1.gz

Navigating faster

pushd and popd: the directory stack

# Save where you are and jump to /var/log
pushd /var/log

# Work somewhere else
cd /etc/nginx

# Jump back to where you were before pushd
popd

# Show the stack with numbers
dirs -v

Think of cd - as one level of undo and pushd/popd as several.

Navigation aliases

Add these to ~/.bashrc, then reload with source ~/.bashrc:

# Common directories
alias logs='cd /var/log'
alias www='cd /var/www/html'
alias configs='cd /etc'

# Shortcuts
alias ..='cd ..'
alias ...='cd ../..'
alias lt='ls -lt | head -20'

Ubuntu already gives you ll, so there is no need to define it again.

Re-running previous commands

# Search history for cd commands
history | grep "cd /"

# Interactive reverse search: press Ctrl+R and start typing
# (press Ctrl+R again to cycle through older matches)

# Re-run the last command that started with cd
!cd

Working with paths

# File name from a path
$ basename /var/log/nginx/error.log
error.log

# Directory from a path
$ dirname /var/log/nginx/error.log
/var/log/nginx

# Absolute path of something relative
realpath ./relative/path

# Resolve a symlink chain (on Ubuntu 24.04 this prints /usr/bin/python3.12)
readlink -f /usr/bin/python3

Troubleshooting: the errors you will actually see

bash: cd: foo: No such file or directory

The path does not exist from where you are. Three usual causes:

  1. Case. Linux filenames are case-sensitive. Documents and documents are different directories.
  2. Relative vs absolute. cd var/log looks for var inside the current directory. You meant cd /var/log.
  3. A typo. Use Tab completion and the problem goes away.

Run pwd and ls to see where you actually are and what is there.

bash: cd: /root: Permission denied

Entering a directory requires execute (search) permission on it, and /root and other users’ homes on Ubuntu are closed to everyone else. Check with ls -ld /root. If you need to look inside, list it with sudo ls -la /root, or open a root shell with sudo -i and then cd.

sudo: cd: command not found

sudo cd /root fails because cd is a shell builtin, not a program sudo can run. Use sudo -i (or sudo -s) to get a root shell, then cd as normal, and exit when you are done.

bash: cd: too many arguments

The directory name has a space in it. Quote it: cd "My Documents".

bash: cd: /etc/hostname: Not a directory

You tried to cd into a file. Use cat or less to read it, or cd into the directory that contains it: cd /etc.

ls: cannot open directory ‘/var/lib/private’: Permission denied

Same cause as the cd case: you lack read permission on that directory. Prefix with sudo if you are entitled to see it.

Hidden files are not showing

Files beginning with a dot (.bashrc, .ssh, .env) are hidden from a plain ls. Add -a or -A.

Cheat sheet

# Where am I?
pwd                     # current directory
pwd -P                  # with symlinks resolved

# What's here?
ls -la                  # everything, long format
ls -lA                  # same, without . and ..
ls -lh                  # human-readable sizes
ls -lt                  # newest first
ls -ltr                 # newest last
ls -lS                  # largest first
ls -ld DIR              # the directory itself

# Moving
cd /path                # absolute
cd dir                  # relative
cd                      # home
cd ..                   # up one
cd -                    # back to previous
cd "name with spaces"   # quote spaces

# Finding
find /path -name "*.txt"    # by name
find /path -mtime -1        # changed in the last 24 hours
find /path -size +100M      # large files
locate filename             # fast index search (plocate)
which command               # where a command lives

# Utilities
pushd /path             # save location, go there
popd                    # return to saved location
realpath ./file         # absolute path

The career translation

Navigation speed shows. In an interview practical or a screen-share during an incident, fumbling around the filesystem reads as inexperience, and moving confidently reads as someone who lives in the terminal. Nobody gets hired for knowing cd. Plenty of people get marked down for visibly not knowing it.

Level What it looks like Role readiness
Slow Types full paths, no Tab Still learning
Basic Uses Tab, knows the filesystem layout Junior ready (£28-35k)
Fluent Aliases, cd -, find, Ctrl+R Mid-level (£35-45k)
Expert Scripted navigation and automation Senior (£45k+)

Practice exercises

  1. Explore a server – Visit /etc, /var/log and /home using only Tab completion, then get back with cd -.
  2. Find the largest log file – Use ls -lS /var/log or find, then go to its directory.
  3. Prove a symlink – Create one with ln -s /var/log ~/logs, cd ~/logs, then compare pwd with pwd -P.
  4. Time yourself – How fast can you get to /var/log/nginx/error.log from anywhere?
The RTM Essential Stack - Gear I Actually Use

Next steps

  • Process management – Now that you can find things, learn to manage what’s running
  • File manipulation – cp, mv, rm, mkdir in depth
  • Scripting – Automate navigation patterns

Navigation is the foundation. Everything else builds on moving confidently through the filesystem.


Part 7 of the Linux Fundamentals series. Next: process management with ps, top, htop, and kill, controlling what runs on your systems.


Linux Fundamentals Series – Part 7 of 12

Previous: Understanding sudo

Next: Process Management: ps, top, kill

View the full series

Enjoyed this guide?

New articles on Linux, homelab, cloud, and automation every 2 days. No spam, unsubscribe anytime.

Scroll to Top