Navigating folders
Your computer's files are organised as a tree of folders (also called directories). Moving around that tree confidently is the first real terminal skill.
The file system tree
/ ← the root: the top of everything
├── home/
│ └── you/ ← your home folder, also written ~
│ ├── Documents/
│ ├── Downloads/
│ ├── projects/
│ │ ├── website/
│ │ └── scripts/
│ └── data/
├── etc/ ← system configuration
├── tmp/ ← temporary files
└── usr/ ← installed programs(On macOS, home is /Users/you. On Windows with WSL, it's /home/you.)
Where am I? What's here?
| Command | Shows |
|---|---|
ls |
Files and folders here |
ls folder |
Contents of another folder |
ls -l |
Long format: permissions, size, date |
ls -a |
All, including hidden files (names starting with ., like .bashrc) |
ls -lh |
Long format with human-readable sizes (K, M, G) |
tree |
A visual tree (often needs installing on real machines) |
Moving with cd
cd means change directory.
| Command | Goes to |
|---|---|
cd folder |
A folder inside the current one |
cd .. |
Up one level (the parent folder) |
cd ../.. |
Up two levels |
cd ~ or just cd |
Your home folder |
cd - |
Back to the previous folder (toggle) |
cd / |
The root of the file system |
Notice how the prompt changes to show where you are: you@learn:~/projects/website$.
Absolute vs relative paths
A path is an address of a file or folder.
- Absolute paths start from the root
/, and they work from anywhere:/home/you/projects/website - Relative paths start from where you are now:
projects/website,../data
| Symbol | Means |
|---|---|
/ at the start |
The root |
~ |
Your home folder |
. |
The current folder |
.. |
The parent folder |
Tip: paths with spaces need quotes,
cd "My Documents", or escaping,cd My\ Documents. That's why developers usually avoid spaces in file names and usemy-documents.
See the whole tree
Practice: treasure hunt 🗺️
Using only cd, ls and pwd:
- Start in your home folder. Go into
projects/websiteand list the files. - Without going home first, go to the
datafolder using a relative path (hint:../..). - Jump back to
websitewithcd -. - Go to
/etcwith an absolute path and look at what's there. What's insideos-release? (Trycat os-release.)
✎ Check your understanding
1.You're in /home/you/projects/website. Where does cd .. take you?
2.Which is an absolute path?