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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts