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.
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.
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).
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?
Moves to the home directoryMoves to the parent directoryLists hidden filesGoes to the root directory
Show answer
Answer: Moves to the parent directory