I don't want any answer saying that there's no need, please!
Use Gparted to defrag your file system
If you have enough space on your hard drive, you can use Gparted to defrag your file system (ext2, ext 4, nfts, etc.). You have to boot from a CD/DVD/USB boot disc because the drive you're working on has to be unmounted. You also have to have more unused space available than used space for this to work and it may take a while.
With the partition you want to defrag as the last partition on the drive:
It's now defragged.
And I know you're not interested in why/why not to defrag ubuntu, but I'll post the link to why-is-defragmentation-unnecessary anyway.
Take a look on e2fsprogs. This is also available in the Ubuntu packages. It provides the program e4defrag.
Use e4defrag to defrag your files
If your ext4 file system is created with the
Just check fragmentation level with something like this (you need to be root to see details):
Here's an example of the output you can get:
As in this example, most of the time it will tell you that no defragmentation is needed, but if you want to do it anyways you can use:
Your users can even run it on their own files, there's no need to be root unless you want to work on other user's or system files.