This program will attempt to reduce the fragmentation of files stored on a Linux system. It uses the "filefrag" tool included in the e2fsprogs version 1.35 and higher package (local mirror with rpms).

The tool depends on the files being quiet - please make sure there's no chance that they'll be modified. I'd suggest changing to single user mode if you have any question about whether the file might be modified.

Unlike other defragmenters, the filesystem stays mounted.

As of version 0.4.1, it has had a good amount of testing on ext3 (so will work just as well on ext2). I've also had a success report on Reiserfs (thanks Josh!). It really should work just fine on any filesystem where filefrag works.

Sample invocation:

find /usr/share/doc/ -type f -a -size +4096c -print | while read onefile ; do defragfile "$onefile" ; done

sudo find /usr/src/uml-linux/ /usr/src/linux-* -type f -a -size +65536c -print | xargs sudo filefrag | grep -v ': 1 extent found' | sed -e 's/: [0-9]* extent.*//' | while read onefile ; do /usr/src/defragfile/defragfile "$onefile" ; done