Bash Tutorial · Bash Basics · Lesson 4 of 30

Bash Navigating the File System

Move around with pwd, cd and ls, and understand absolute and relative paths.

Create a free account to save this page, take notes and track your progress. Sign in

Where am I?

pwd prints the working directory. Paths starting with / are absolute; others are relative to the working directory. . is the current directory, .. its parent, and ~ your home directory.

pwd, cd and relative paths
mkdir -p projects/shop/src
cd projects/shop
pwd | sed "s|$HOME|~|"
cd src
cd ..
basename "$(pwd)"
cd ../..
ls

Output

~/projects/shop
shop
projects

Run this on your computer — see “Get Started” for setup.

Listing files

Useful ls options: -l (long format), -a (include hidden dot-files), -h (human-readable sizes), -t (sort by time), -R (recursive).

ls options
mkdir docs
touch docs/readme.md docs/.hidden notes.txt
ls
ls -a docs
ls -R

Output

docs
notes.txt
.
..
.hidden
readme.md
.:
docs
notes.txt

./docs:
readme.md

Run this on your computer — see “Get Started” for setup.

cd - jumps back to the previous directory, and cd alone goes home.

Test yourself

What does cd .. do?

  1. Moves to the home directory
  2. Moves to the parent directory
  3. Lists hidden files
  4. Goes to the root directory
Show answer

Answer: Moves to the parent directory

Was this page helpful?