Advanced file system
Table of contents
- Types of file systems
- Inodes and internal structure
- Symbolic links vs hard links
- Commands: ln, stat, df, du
- Hands-on exercises
1 - Types of file systems
What is a file system?
A file system organizes how data is stored and retrieved on a disk.
Linux file systems
| Type | Usage | Characteristics |
|---|---|---|
| ext4 | Linux standard | Journaled, stable, performant |
| xfs | Enterprise | High performance, large files |
| btrfs | Modern | Snapshots, compression |
| zfs | Advanced | Data integrity, RAID |
| ntfs | Windows | Read/write with ntfs-3g |
| fat32/exfat | USB | Universal compatibility |
| tmpfs | RAM | Ultra-fast temporary files |
View the file system
# Voir les systèmes de fichiers montés
df -T
# Exemple de sortie
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 50G 15G 32G 32% /
tmpfs tmpfs 4.0G 0 4.0G 0% /dev/shm
# Informations détaillées d'une partition
sudo file -s /dev/sda1
# Type du système de fichiers d'un point de montage
stat -f / | grep Type
Important characteristics
| Characteristic | Description |
|---|---|
| Journaling | Recovery after a crash |
| Max file size | Size limit per file |
| Max volume size | Total size limit |
| Permissions | POSIX support |
| ACL | Extended permissions |
🔝 Back to table of contents
2 - Inodes and internal structure
What is an inode?
An inode (index node) is a data structure that contains a file's metadata.
Content of an inode
| Information | Description |
|---|---|
| Type | File, directory, link... |
| Permissions | rwx for user/group/others |
| Owner | UID and GID |
| Size | In bytes |
| Timestamps | atime, mtime, ctime |
| Link counter | Number of hard links |
| Pointers | To the data blocks |
The inode does NOT contain the file name! The name is stored in the parent directory.
View the inodes
# Afficher le numéro d'inode
ls -i fichier.txt
# 12345678 fichier.txt
# Détails complets avec stat
stat fichier.txt
Output of stat:
File: fichier.txt
Size: 1234 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 12345678 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ john) Gid: ( 1000/ john)
Access: 2024-01-15 10:30:00.000000000 +0000
Modify: 2024-01-15 10:25:00.000000000 +0000
Change: 2024-01-15 10:25:00.000000000 +0000
Birth: 2024-01-15 10:20:00.000000000 +0000
Timestamps
| Timestamp | Meaning | Updated when |
|---|---|---|
| atime | Access time | The file is read |
| mtime | Modify time | Content is modified |
| ctime | Change time | Metadata is modified |
Inode limit
# Voir l'utilisation des inodes
df -i
# Exemple
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 3276800 234567 3042233 8% /
You can run out of inodes before running out of disk space! This happens with many small files.
🔝 Back to table of contents
3 - Symbolic links vs hard links
Hard link
A hard link creates a new directory entry pointing to the same inode.
# Créer un lien physique
ln fichier.txt lien_physique.txt
# Vérifier : même inode
ls -li fichier.txt lien_physique.txt
# 12345 -rw-r--r-- 2 john john 100 Jan 15 fichier.txt
# 12345 -rw-r--r-- 2 john john 100 Jan 15 lien_physique.txt
Characteristics:
- Same inode, same data
- The file exists as long as one link exists
- Cannot cross file systems
- Cannot point to a directory
Symbolic link (symlink)
A symbolic link is a special file that points to a path.
# Créer un lien symbolique
ln -s fichier.txt lien_symbolique.txt
# Vérifier
ls -l lien_symbolique.txt
# lrwxrwxrwx 1 john john 11 Jan 15 lien_symbolique.txt -> fichier.txt
# Différent inode
ls -li fichier.txt lien_symbolique.txt
Characteristics:
- Different inode, special file
- Can point to directories
- Can cross file systems
- Becomes broken if the target is deleted
Comparison
| Aspect | Hard link | Symbolic link |
|---|---|---|
| Inode | Same | Different |
| Directories | No | Yes |
| Cross-filesystem | No | Yes |
| Size | Identical | Size of the path |
| If target deleted | Data preserved | Broken link |
| Command | ln | ln -s |
🔝 Back to table of contents
4 - Commands: ln, stat, df, du
ln - Create links
# Lien physique
ln source.txt hardlink.txt
# Lien symbolique
ln -s source.txt symlink.txt
# Lien symbolique vers répertoire
ln -s /var/log logs
# Forcer le remplacement
ln -sf nouvelle_cible.txt symlink.txt
# Verbose
ln -sv source.txt symlink.txt
stat - Detailed information
# Informations complètes
stat fichier.txt
# Format personnalisé
stat --format='%n: %s bytes, inode %i' fichier.txt
# fichier.txt: 1234 bytes, inode 12345678
# Formats utiles
stat -c '%a' fichier.txt # Permissions octales (644)
stat -c '%U:%G' fichier.txt # user:group
stat -c '%y' fichier.txt # Date modification
df - Disk space (partitions)
# Affichage lisible
df -h
# Avec type de filesystem
df -hT
# Une partition spécifique
df -h /home
# Inodes
df -i
Example output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 15G 32G 32% /
/dev/sda2 100G 60G 35G 63% /home
tmpfs 4.0G 0 4.0G 0% /dev/shm
du - Used space (files/folders)
# Taille d'un dossier
du -sh /var/log
# Taille de chaque sous-dossier
du -h --max-depth=1 /var
# Top 10 des plus gros dossiers
du -h /var | sort -rh | head -10
# Exclure certains fichiers
du -sh --exclude='*.log' /var
# Taille totale de plusieurs éléments
du -ch *.txt
Practical examples
# Trouver les gros fichiers
find / -type f -size +100M 2>/dev/null
# Espace utilisé par utilisateur
sudo du -sh /home/*
# Vérifier avant de manquer d'espace
df -h | awk '$5 > 80 {print "ALERTE:", $6, "à", $5}'
🔝 Back to table of contents
5 - Hands-on exercises
Exercise 1: Explore the inodes
# 1. Créez un fichier
echo "Hello" > test.txt
# 2. Affichez son inode
ls -i test.txt
# 3. Affichez les détails complets
stat test.txt
# 4. Notez le nombre de liens (Links: 1)
Exercise 2: Hard and symbolic links
# 1. Créez un fichier source
echo "Contenu original" > original.txt
# 2. Créez un lien physique
ln original.txt hardlink.txt
# 3. Créez un lien symbolique
ln -s original.txt symlink.txt
# 4. Comparez les inodes
ls -li original.txt hardlink.txt symlink.txt
# 5. Modifiez via le lien physique
echo "Modification" >> hardlink.txt
cat original.txt # Vérifie que c'est modifié
# 6. Supprimez l'original
rm original.txt
# 7. Testez les liens
cat hardlink.txt # Fonctionne (même inode)
cat symlink.txt # Erreur (lien cassé)
Exercise 3: Disk space
# 1. Vérifiez l'espace global
df -h
# 2. Trouvez les 5 plus gros dossiers dans /var
sudo du -h /var --max-depth=1 | sort -rh | head -5
# 3. Vérifiez les inodes
df -i
Quiz
Q1. Which piece of information is NOT stored in the inode?
Answer
The file name! It is stored in the parent directory.
Q2. Can you create a hard link to a directory?
Answer
No, only symbolic links can point to directories.
Q3. Which command displays disk space per partition?
Answer
df -h (disk free)
🔝 Back to table of contents
Key takeaways
- ext4 is the standard Linux file system
- The inode contains the metadata but NOT the name
- Hard link = same inode, symbolic link = path
df -h= space per partition,du -sh= space per folder- You can run out of inodes before running out of space
statgives all the information about a file