Wiki pages for btrfs and other how-tos talk about online defragmentation and other related topics but they don't say how to find out how fragmented a file system is. Is there a method to determine how many files are fragmented or to produce some other meassure of file system fragmentation?
1 Answer
filefrag
command works with btrfs as well as with other filesystems.
$ filefrag ubuntu-8.04.1-desktop-i386.iso
ubuntu-8.04.1-desktop-i386.iso: 7 extents found
It only shows the number of extents for individual files though. You may want to write a shell script to sample a number of files and calculate some number which will give an approximate indication of how the whole filesystem is fragmented.