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.
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
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.cdwith no argument: same ascd ~.
Absolute and relative paths
An absolute path always starts from the root of the file system (/ on macOS/Linux, /c/ in Git Bash):
A relative path starts from the current folder. There is no / at the beginning:
.refers to the current folder...refers to the parent folder.~always refers to your home, no matter where you are.
Exploring with ls
-l: long format (permissions, owner, size, date).-a: includes hidden files (.gitignore,.env, etc.).-h: human-readable sizes (4.2Minstead of4392448).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.
