Defragmenting disks in Linux through the command line

Yes, you have probably read that in Linux it is not necessary to defragment disks, this is because the file systems that Linux uses (EXT, EXT4…) are more efficient when it comes to hosting files on disks compared to the ones we know in Windows (FAT32, NTFS…), but it is still necessary to defragment them from time to time.

There are several file defragmenters for Linux, but as usual, I will only talk about the one I have been using for many years, e4defrag, and so far it has always given me very good results.

In case it is not installed on your system, the first thing to do is to install it:

sudo apt-get install e2fsprogs

Once installed, using it is very simple, just use the command “sudo e4defrag” followed by the path you want to defragment.

If we want to defragment only a folder of our home, it would be:

sudo e4defrag /home/mitsuha

We can also defragment specific drives, for example, suppose we have a disk mounted in /mnt/sda, we would only have to use the command:

sudo e4defrag /mnt/sda

When using the command, it will provide us with a console output, where it will indicate the number of files checked and defragmented and the total, in addition, we can see the file that is processing along with the progress and its status.

So easy, we let the program finish and we will have defragmented the disk or the path we have specified.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.