Skip to main content

Navigating the file system


Table of contents

  1. The Linux directory structure
  2. The pwd command - Where am I?
  3. The ls command - List the contents
  4. The cd command - Move around
  5. Absolute vs relative paths
  6. 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

DirectoryContentExample
/Root, everything starts here-
/homeUsers' personal folders/home/john
/rootRoot's personal folder-
/etcConfiguration files/etc/passwd
/varVariable data (logs, cache)/var/log
/tmpTemporary files-
/usrPrograms and libraries/usr/bin
/binEssential commands/bin/ls
/sbinSystem commands/sbin/reboot
/optOptional software-
/devDevice files/dev/sda
/procProcess information/proc/cpuinfo
/mntTemporary mount points-
/mediaRemovable media (USB, CD)-
The home directory

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.

tip

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

OptionEffectExample
-lLong format (details)ls -l
-aShow hidden filesls -a
-hHuman-readable sizes (KB, MB)ls -lh
-RRecursive (subfolders)ls -R
-tSort by datels -lt
-SSort by sizels -lS
-rReverse orderls -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

SymbolType
-Normal file
dDirectory
lSymbolic link
cCharacter device
bBlock 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

CommandDestination
cdHome (~)
cd ~Home
cd -Previous directory
cd ..Parent
cd ../..Grandparent
cd /Root
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:~$
Auto-completion

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

SymbolMeaning
/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:

AbsoluteRelativeDestination
/home/user/DocumentsDocumentsDocuments
/home/user/Documents./DocumentsDocuments
/home..Parent
/var/log../../var/log/var/log
/etc/etc/etc (always absolute)

When to use what?

SituationRecommendation
ScriptsAbsolute paths (reliability)
Fast navigationRelative paths
DocumentationAbsolute paths (clarity)
Nearby filesRelative 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?

DestinationAbsolute pathRelative path
/home/user/Documents/home/user/DocumentsDocuments
/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? (-la to see everything)
  • cd = go somewhere
  • ~ = home, .. = parent, / = root
  • Absolute path = from the root (/home/user)
  • Relative path = from here (Documents)

🔝 Back to table of contents


← Previous chapter | Next chapter: Managing files →