Linux Find And Report On File Fragmentation

You can use the filefrag utility to find and report on file fragmentation on a Linux system. filefrag displays the extent map of a file, which shows how the file is divided into fragments and where those fragments are located on the disk.

Here’s how you can use filefrag:

  1. Install e2fsprogs package:
    sudo apt-get install e2fsprogs
  2. Use the filefrag utility to report on a specific file:
    filefrag <filename>

Example:

filefrag large_file.txt
Filesystem type is: ef53
File size of large_file.txt is 1073741824 (1024.00 MiB)
ext: logical_offset: physical_offset: length: expected: flags:
0: 0.. 8388607: 657701120.. 741191927: 8388608: 8388608:
1: 8388608..16777215: 741191936.. 824682743: 8388608: 8388608:
2: 16777216..25165823: 824682752.. 908173559: 8388608: 8388608:
3: 25165824..33554431: 908173568.. 991664375: 8388608: 8388608:

Explanation:

  • ext is the extent number.
  • logical_offset is the offset of the extent in the file, in bytes.
  • physical_offset is the offset of the extent on the disk, in bytes.
  • length is the size of the extent, in bytes.
  • expected is the ideal length of the extent, in bytes.
  • flags is a set of flags that indicate the type of the extent (e.g. unwritten).

Note: The filefrag utility is part of the e2fsprogs package, which is not installed by default on all Linux distributions.

Leave a Comment