Skip to main content

Advanced file system


Table of contents

  1. Types of file systems
  2. Inodes and internal structure
  3. Symbolic links vs hard links
  4. Commands: ln, stat, df, du
  5. 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

TypeUsageCharacteristics
ext4Linux standardJournaled, stable, performant
xfsEnterpriseHigh performance, large files
btrfsModernSnapshots, compression
zfsAdvancedData integrity, RAID
ntfsWindowsRead/write with ntfs-3g
fat32/exfatUSBUniversal compatibility
tmpfsRAMUltra-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

CharacteristicDescription
JournalingRecovery after a crash
Max file sizeSize limit per file
Max volume sizeTotal size limit
PermissionsPOSIX support
ACLExtended 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

InformationDescription
TypeFile, directory, link...
Permissionsrwx for user/group/others
OwnerUID and GID
SizeIn bytes
Timestampsatime, mtime, ctime
Link counterNumber of hard links
PointersTo the data blocks
Important

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

TimestampMeaningUpdated when
atimeAccess timeThe file is read
mtimeModify timeContent is modified
ctimeChange timeMetadata 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% /
warning

You can run out of inodes before running out of disk space! This happens with many small files.

🔝 Back to table of contents



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

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

AspectHard linkSymbolic link
InodeSameDifferent
DirectoriesNoYes
Cross-filesystemNoYes
SizeIdenticalSize of the path
If target deletedData preservedBroken link
Commandlnln -s

🔝 Back to table of contents



4 - Commands: ln, stat, df, du

# 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)
# 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
  • stat gives all the information about a file

🔝 Back to table of contents


Next chapter: Storage management →