Learn

Navigating files

Terminal

cd, pwd, ls, and the concepts of relative and absolute paths.

Before you can manipulate files, you need to know where you are and how to move around. This lesson covers cd, pwd, and the difference between relative and absolute paths.

The current folder

The shell always has a "current folder" (also called "working directory"). All commands you type run from that folder by default.

shell
pwd

pwd tells you exactly where you are. The result looks like /Users/vicente (macOS/Linux) or /c/Users/bloki (Git Bash on Windows).

Moving around with cd

shell
cd documents
cd /Users/vicente/Desktop
cd ..
cd ~
cd -
  • cd <folder>: enters the given folder.
  • cd ..: goes up one level (the parent folder).
  • cd ~: goes directly to your home folder from anywhere.
  • cd -: returns to the previous folder. Handy when switching between two locations.
  • cd with no argument: same as cd ~.

Absolute and relative paths

An absolute path always starts from the root of the file system (/ on macOS/Linux, /c/ in Git Bash):

shell
cd /Users/vicente/Desktop/my-project

A relative path starts from the current folder. There is no / at the beginning:

shell
cd my-project
cd ../other-project
cd ./subfolder
  • . refers to the current folder.
  • .. refers to the parent folder.
  • ~ always refers to your home, no matter where you are.

Exploring with ls

shell
ls
ls -l
ls -la
ls documents/
ls -lh
  • -l: long format (permissions, owner, size, date).
  • -a: includes hidden files (.gitignore, .env, etc.).
  • -h: human-readable sizes (4.2M instead of 4392448).
  • ls <path>: lists the contents of another folder without going there.

History and autocompletion

The shell remembers all your commands. Two essential shortcuts:

  • Up arrow / down arrow: navigate through your history.
  • Ctrl+R: search through history. Type a few letters and the shell finds the last matching command. Press Ctrl+R again to go further back.
Command-line editing (GNU Bash manual)

Check off steps to unlock what comes next

Back to course