Linux Filesystem Fragmentation

filefrag — report file fragmentation

filefrag reports extent layout and fragmentation information for files on disk.

What filefrag is good for

Some filesystems may not support detailed extent reporting. Root privileges may be required for full information.

10 Practical Examples

1) Basic fragmentation report

filefrag file.txt

2) Verbose output

filefrag -v file.txt

3) Check multiple files

filefrag *.log

4) Show physical block layout

sudo filefrag -v largefile.img

5) Count extents only

filefrag -v file.txt | grep extent

6) Analyze large database file

filefrag -v database.db

7) Use with find

find /data -type f -size +100M -exec filefrag -v {} \;

8) Compare before/after defragmentation

filefrag -v file.txt
sudo e4defrag file.txt
filefrag -v file.txt

9) Check filesystem support

findmnt -o TARGET,FSTYPE

10) Script-friendly check

filefrag file.txt | awk '{print $2}'