La great robustness of file systems (FS) that are used in GNU / Linux systems has made users fall into an error, thinking that it is not necessary to defragment the hard disk as it happens in Windows. This is not entirely true, although it is not as necessary and vital as in Microsoft systems, it is good to do it.
The systems ZFS, EXT, JFS, XFS, ReiserFS, Btrfs, etc., they have intelligent allocation systems for the files that avoid that sharp and horrible fragmentation that occurs in Windows, but that does not mean that the problem does not exist. Years can pass after the installation of your distribution and fragmentation would not be a problem, even if you use it intensively and install and uninstall libraries, etc.
However, some users with limited hard disk space they may be more marked by the problem of fragmentation. Limited space makes it more difficult for these filesystems to allocate spaces to new files. That is why I recommend installing a tool to defragment your hard drive. There are many, such as e4defrag (which you probably don't even have to install because it is already installed by default in your distribution).
Its use is very simple, you just have to open a terminal window and type the following:
sudo e4defrag -c /ruta
Replace / path with the partition or device you want to defragment. For example: “sudo e4defrag -c / dev / sda1” or it can be a single folder “sudo e4defrag -c / home”. But be careful, this will only tell you the amount of files that have been found fragmented. If the number is low you have no reason to defragment, but if it goes above 30 you should consider defragmenting. To defrag all partitions:
sudo e4defrag /dev/sda*
In case you only want to defragment a specific directory, you can use for example "/ home" instead of "/ dev / sda *" or even specify the partition "/ dev / sda5". If you have an SSD, you don't have to worry from this, defragmentation only makes sense on magnetic hard drives ... SSDs are so fast that it is not worth it and also, defragmenting only increases the read / write cycles and therefore decreases the useful life of your drive.