GNU+Linux command memo

Defrag Ext4 file system with shake

Les systèmes de fichiers ext3 / ext4 etc. fragmentent. Peu, pas vite, mais au bout de 6 ans ça ralentit l’ordinateur. Il existe la commande shake pour défragmenter.

Ext file systems are fragmenting. A little bit, slowly, but after a quite some years it slows down a computer. That’s why it exists the shake command, to defrag old systems. shake is a defragmenter that runs in userspace, without the need of patching the kernel and while the system is used (for now, on GNU/Linux only).

Using Arch Linux the shake command is available as a PKGBBUILD. Using Debian there is a third-party repository ( or it’s easy to compile.

First, check that your partition is mounted with the user_xattr option, else edit your /etc/fstab to add this option then call mount -o remount MY_PARTITION. Shake can works without them, but will be less efficient (it use xattr to store information helping incremental use).

Then, you can check the fragmentation of a directory or a whole unmounted partition with :

# shake --pretend --verbose --verbose $my_dir  (1) (2)
1 launched as root
2 $my_dir should be replace with an existing directory

And reduce it via :

# shake $my_dir (1)
# find -iname '*.mp3' | sort | shake (2)
1 to defrag the $my_dir directory
2 to defrag all MP3 in a directory, puting together on the disk those close in lexical order
Better avoid shaking : /proc /sys /dev /tmp or /run ; it’s useless
SSD storages are less affected (nearly not at all) by fragmentation, it’s their normal way of operation. But rescue utilities (such as : fsck or photorec) are way faster on defragmented filesystems, so better keep it defragmented and let the storage microcontroller manage hardware fragmentation / wear balance.
More information of the official website of the project :