Navigating the file system
Table of contents
- The Linux directory structure
- The pwd command - Where am I?
- The ls command - List the contents
- The cd command - Move around
- Absolute vs relative paths
- Hands-on exercises
1 - The Linux directory structure
Linux organizes all files in a single directory tree starting from the root /.
The Linux directory tree
Main directories
| Directory | Content | Example |
|---|---|---|
/ | Root, everything starts here | - |
/home | Users' personal folders | /home/john |
/root | Root's personal folder | - |
/etc | Configuration files | /etc/passwd |
/var | Variable data (logs, cache) | /var/log |
/tmp | Temporary files | - |
/usr | Programs and libraries | /usr/bin |
/bin | Essential commands | /bin/ls |
/sbin | System commands | /sbin/reboot |
/opt | Optional software | - |
/dev | Device files | /dev/sda |
/proc | Process information | /proc/cpuinfo |
/mnt | Temporary mount points | - |
/media | Removable media (USB, CD) | - |
Your personal directory is /home/your_name. That is where you store your files. The ~ symbol is a shortcut for this directory.
🔝 Back to table of contents
2 - The pwd command - Where am I?
pwd = Print Working Directory
This command displays the full path of the directory you are in.
Usage
pwd
Examples
# Après ouverture du terminal
user@ubuntu:~$ pwd
/home/user
# Après avoir changé de répertoire
user@ubuntu:/etc$ pwd
/etc
# À la racine
user@ubuntu:/$ pwd
/
Why is it important?
The prompt often shows an abbreviated version of the path:
~instead of/home/user- Just the last directory
pwd gives you the complete and exact path.
When you are lost, type pwd to know exactly where you are!
🔝 Back to table of contents
3 - The ls command - List the contents
ls = List
This command lists the files and folders in a directory.
Basic usage
# Lister le répertoire courant
ls
# Lister un répertoire spécifique
ls /etc
ls /home
Common options
| Option | Effect | Example |
|---|---|---|
-l | Long format (details) | ls -l |
-a | Show hidden files | ls -a |
-h | Human-readable sizes (KB, MB) | ls -lh |
-R | Recursive (subfolders) | ls -R |
-t | Sort by date | ls -lt |
-S | Sort by size | ls -lS |
-r | Reverse order | ls -lr |
Useful combinations
# Liste détaillée avec fichiers cachés et tailles lisibles
ls -lah
# Liste triée par date (récent en premier)
ls -lt
# Liste triée par taille (gros fichiers en premier)
ls -lSh
Understanding ls -l
-rw-r--r-- 1 user group 4096 Jan 15 10:30 fichier.txt
│├──┬───┤ │ │ │ │ │ │
││ │ │ │ │ │ │ │ └── Nom du fichier
││ │ │ │ │ │ │ └── Date de modification
││ │ │ │ │ │ └── Taille en octets
││ │ │ │ │ └── Groupe propriétaire
││ │ │ │ └── Utilisateur propriétaire
││ │ │ └── Nombre de liens
││ │ └── Permissions autres
││ └── Permissions groupe
│└── Permissions propriétaire
└── Type (- = fichier, d = dossier, l = lien)
File types
| Symbol | Type |
|---|---|
- | Normal file |
d | Directory |
l | Symbolic link |
c | Character device |
b | Block device |
Colors in ls
By default, ls colors the results:
- Blue: Directories
- White: Normal files
- Green: Executable files
- Cyan: Symbolic links
- Red: Compressed archives
🔝 Back to table of contents
4 - The cd command - Move around
cd = Change Directory
This command lets you navigate between directories.
Syntax
cd [répertoire]
Common uses
# Aller dans un répertoire
cd Documents
# Aller au répertoire parent
cd ..
# Aller à la racine
cd /
# Aller dans son home
cd ~
# ou simplement
cd
# Aller au répertoire précédent
cd -
Relative navigation
# Depuis /home/user
cd Documents # Va dans /home/user/Documents
cd .. # Revient à /home/user
cd ../.. # Va à /home
cd ./Documents # Va dans /home/user/Documents (. = ici)
Absolute navigation
# Peu importe où vous êtes
cd /var/log # Va directement dans /var/log
cd /home/user/Documents
cd /etc/nginx
Handy shortcuts
| Command | Destination |
|---|---|
cd | Home (~) |
cd ~ | Home |
cd - | Previous directory |
cd .. | Parent |
cd ../.. | Grandparent |
cd / | Root |
Navigation example
user@ubuntu:~$ pwd
/home/user
user@ubuntu:~$ cd /var/log
user@ubuntu:/var/log$ pwd
/var/log
user@ubuntu:/var/log$ cd -
/home/user
user@ubuntu:~$ cd Documents
user@ubuntu:~/Documents$ cd ..
user@ubuntu:~$
Use Tab to complete directory names:
cd Doc[Tab] → cd Documents/
🔝 Back to table of contents
5 - Absolute vs relative paths
Absolute path
An absolute path always starts with / and indicates the full path from the root.
/home/user/Documents/projet/fichier.txt
│
└── Commence par /
Advantage: Works from anywhere
# Depuis n'importe quel répertoire
cat /home/user/Documents/notes.txt
Relative path
A relative path starts from the current directory.
Documents/projet/fichier.txt
│
└── Ne commence PAS par /
Advantage: Shorter to type
# Depuis /home/user
cat Documents/notes.txt
Special symbols
| Symbol | Meaning |
|---|---|
/ | Root (at the start) or separator |
~ | Home of the current user |
. | Current directory |
.. | Parent directory |
- | Previous directory (with cd) |
Comparative examples
Suppose you are in /home/user:
| Absolute | Relative | Destination |
|---|---|---|
/home/user/Documents | Documents | Documents |
/home/user/Documents | ./Documents | Documents |
/home | .. | Parent |
/var/log | ../../var/log | /var/log |
/etc | /etc | /etc (always absolute) |
When to use what?
| Situation | Recommendation |
|---|---|
| Scripts | Absolute paths (reliability) |
| Fast navigation | Relative paths |
| Documentation | Absolute paths (clarity) |
| Nearby files | Relative paths |
🔝 Back to table of contents
6 - Hands-on exercises
Exercise 1: Exploration
# 1. Affichez votre répertoire courant
pwd
# 2. Listez le contenu de votre home
ls -la ~
# 3. Allez dans /etc et listez le contenu
cd /etc
ls
# 4. Revenez dans votre home
cd ~
Exercise 2: Navigation
# Depuis votre home, effectuez ces déplacements :
# 1. Allez dans /var/log
cd /var/log
# 2. Vérifiez où vous êtes
pwd
# 3. Listez les fichiers (format long)
ls -lh
# 4. Remontez de 2 niveaux
cd ../..
# 5. Où êtes-vous ?
pwd
# Réponse attendue : /
Exercise 3: Paths
From /home/user, how do you reach these destinations?
| Destination | Absolute path | Relative path |
|---|---|---|
/home/user/Documents | /home/user/Documents | Documents |
/etc | /etc | ../../etc |
/home | /home | .. |
/tmp | /tmp | ../../tmp |
Quiz
Q1. Which command displays the current directory?
Answer
pwd
Q2. How do you list hidden files?
Answer
ls -a or ls -la
Q3. How do you go back to the previous directory?
Answer
cd -
Q4. What does ~ mean?
Answer
The home directory of the current user
🔝 Back to table of contents
Key takeaways
- Linux organizes everything in a directory tree starting from
/ pwd= where am I?ls= what's here? (-lato see everything)cd= go somewhere~= home,..= parent,/= root- Absolute path = from the root (
/home/user) - Relative path = from here (
Documents)