How do I find file fragmentation for specific file under Linux?

If you would like to find out file fragmentation information for specific file, use filefrag command that report on file fragmentation.

filefrag reports on how badly fragmented a particular file might be. It makes allowances for indirect blocks for ext2 and ext3 filesystems, but can be used on files for any filesystem.

For example see file fragmentation for /var/log/message file:

# filefrag -v /var/log/messages

Output:

Checking /var/log/messages
Filesystem type is: ef53
Filesystem cylinder groups is approximately 9448
Blocksize of file /var/log/messages is 4096
File size of /var/log/messages is 72 (1 blocks)
First block: 1841075
Last block: 1841075
/var/log/messages: 1 extent found

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.