Ever wonder if an individual file is fragmented or not? The little known filefrag utility shipped as part of the e2fsprogs package can answer that question for files on ext2 and ext3 filesystems.
Examples:
# filefrag /usr/bin/bc
/usr/bin/bc: 5 extents found, perfection would be 1 extent
Or the verbose mode:
# filefrag -v /usr/bin/bc
Checking /usr/bin/bc
Filesystem type is: ef53
Filesystem cylinder groups is approximately 4976
Blocksize of file /usr/bin/bc is 4096
File size of /usr/bin/bc is 62636 (16 blocks)
First block: 350680
Last block: 354750
Discontinuity: Block 1 is at 352866 (was 350680)
Discontinuity: Block 5 is at 352981 (was 352869)
Discontinuity: Block 12 is at 352998 (was 352988)
Discontinuity: Block 13 is at 354748 (was 352998)
/usr/bin/bc: 5 extents found, perfection would be 1 extent
To examine fragmentation for an entire ext2/ext3 filesystem use the e2fsck command on the filesystem. When it finishes running it will report fragmentation details.

Leave a comment