≡ Menu

Linux Find And Report On File Fragmentation

How do I find out badly fragmented a particular file might be under Linux operating systems?

You need to use the filefrag command. It reports on how badly fragmented a particular file might be. It makesallowances for indirect blocks for ext2 and ext3 filesystems, but can be used on files for any filesystem. The syntax is:

filefrag file
filefrag files
filefrag file1 file2

In this example find how how badly fragmented rhel-workstation-6.3-x86_64-dvd.iso:
# filefrag /home/vivek/Downloads/rhel-workstation-6.3-x86_64-dvd.iso
Sample outputs:

/home/vivek/Downloads/rhel-workstation-6.3-x86_64-dvd.iso: 2093 extents found

You can verbose when checking for file fragmentation with the -v option:
# filefrag -v /etc/passwd
Sample outputs:

Filesystem type is: ef53
Filesystem cylinder groups is approximately 3547
File size of /etc/passwd is 1808 (1 block, blocksize 4096)
 ext logical physical expected length flags
   0       0 103071773               1 merged,eof
/etc/passwd: 1 extent found

Other options (taken from the man page):

       -B     Force  the  use  of  the  older FIBMAP ioctl instead of the FIEMAP ioctl for
              testing purposes.

       -b     Use 1024 byte blocksize for the output.

       -s     Sync the file before requesting the mapping.

       -x     Display mapping of extended attributes.
Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 1 comment… add one }
  • Jalal Hajigholamali July 27, 2012, 5:35 am


    Thanks a lot, very useful article

    and useful command for admin

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , ,