File system defragmentation is a not as obvious task in Linux/Unix as it is in Windows. Modern Unix file systems are designed to avoid fragmentation. However, in rare cases I explicitly want to defrag my favored XFS partitions, and it’s done this way:
Check fragmentation percentage:
# xfs_db -r -c frag /dev/sdaX
Defrag:
# xfs_fsr /dev/sdaX