How to Defrag in Linux

By Fred Decker

Windows-based computers require regular housekeeping in order to operate at maximum efficiency. Longtime users generally have a list of routine maintenance tasks to perform, such as defragmenting or "defragging" the hard drive. In normal use your computer tends to scatter pieces of files wherever there's room, and over time that can slow its performance dramatically. Users who switch to Linux often assume they'll still need to do this, but that's seldom the case.

Don't Worry

Linux uses a robust and efficient file system. Because of its roots in the older Unix operating system, Linux -- although it's an excellent single-user OS -- was also built to support multiple users in high-volume applications. Its file systems are designed to write the "blocks" of data that make up a file or program onto the same part of your hard drive, or at least keep them very close to each other. In practical terms, as a single user running a desktop version of Ubuntu, Mint or other popular Linux distributions, it's unlikely you'll ever need to defrag your drive.

The Exception

Users who frequently write and delete massive files such as full-length movies might eventually benefit from defragging. If you're comfortable using the Linux command line interface, or CLI, a utility called "defragfs" works well. Download the utility from its Sourceforge project page or other source and copy the file to your /usr/bin directory. Type "make defragfs" -- without the quote marks -- at your command prompt to unpack the utility. To see if your drive really needs defragmentation, type "defragfs /mnt/hda1" -- again, without the quotes -- replacing hda1 if necessary with the actual name of your drive. Follow the prompts to defragment your drive, if necessary, or to cancel.