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?
Ubuntu – How to show the current amount of fragmentation on a btrfs filesystem
btrfsdefrag
Best Answer
filefrag
command works with btrfs as well as with other filesystems.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.