Module lessons (2/2)
Moving around the file system (cd)
In the terminal you don't navigate by double-clicking icons: you move the working directory cursor using cd (Change Directory). Understanding where a path is resolved from avoids the most common mistake made by beginners: No such file or directory.
Absolute vs Relative and shortcuts
| Path shape | Starting point | Example | When it is best to use it |
|---|---|---|---|
Absolute (/...) | Always from the root / | cd /home/user/documents | In scripts or when you jump away from the current branch |
Relative (dir/...) | From current CWD | cd documents | When you are already close to your destination and want speed |
.. | Instant parent folder | cd .. or cd ../logs | To go up one or more levels towards root |
. | Current folder itself | ls . | When a command requires a local explicit path |
~ | Your home (/home/user) | cd ~ (or just cd) | To go home immediately from anywhere in the system |
Progressive examples
1. Enter with a relative path and verify with pwd
pwd
# /home/user
cd documents
pwd
# /home/user/documents2. Go up one level with .. and chain levels
pwd
# /home/user/documents
cd ..
pwd
# /home/userEven outside the home page you can concatenate multiple .. with the slash: for example cd ../.. goes up two levels in a single command.
3. Use absolute paths from any location
cd /home/user/documents
pwd
# /home/user/documentsA route starting with / completely ignores where you are at that moment.
4. Return to home with ~ and recognize the incorrect paths
cd cartella_inesistente
# cd: cartella_inesistente: No such file or directory
cd ~
pwd
# /home/userPractical exercises
Step 1 — Relative movement
Move inside the 'documents' folder using a relative path.
Show hint
Use the cd command followed by a space and the name documents.
Solution available after 3 attempts
Step 2 — Trace the parent
Go back to the parent (parent) folder of your current location.
Show hint
Use a colon (..) instead of a single period to indicate the parent directory.
Solution available after 3 attempts
Step 3 — Return to the home page and back
Move inside the 'documents' folder and immediately return to your home directory using the special shortcut ~.
Show hint
Add the cd ~ command to the second line to return to /home/user.
Solution available after 3 attempts
Quick check
Your current pwd is /home/user. Which command tries to enter the wrong location and generates No such file or directory?
You are at /home/user/documents and execute cd .. followed by pwd. What does the shell print?