Command Line Navigation
Move around the filesystem and inspect directories from the terminal
Overview
Navigation is the foundation of working in a shell: you always operate from a "current working directory," and every command runs relative to it. Knowing how to move between folders, see where you are, and list contents lets you do everything else with confidence. Getting comfortable here removes most of the fear beginners have of the terminal.
Syntax / Usage
Use pwd to print your location, ls to list contents, and cd to change directory.
pwd # print working directory
ls # list files in current directory
ls -la # long format, including hidden dotfiles
cd /etc # go to an absolute path
cd projects # go to a subdirectory (relative path)
cd .. # go up one level to the parent
cd ~ # go to your home directory
cd - # jump back to the previous directory
Examples
Check where you are, then look at everything including hidden files:
pwd
ls -la
Move into a nested project folder and confirm the move:
cd ~/code/stackademic
pwd
Bounce between two directories while comparing files:
cd /var/log
cd ~/notes
cd - # returns to /var/log
Common Mistakes
- Confusing absolute paths (start with
/) and relative paths (start from where you are) - Forgetting that
lshides dotfiles unless you pass-a - Typing
cd..without a space; the command iscd .. - Assuming
cdwith no argument fails — it actually returns you home - Not using tab completion, leading to typos in long directory names
See Also
command-line-files-and-directories command-line-environment-variables