LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

e4defrag

ext4 filesystem defragmentation tool

TLDR

Defragment a whole mounted filesystem
$ sudo e4defrag [/dev/sdXN]
copy
Defragment a single file
$ sudo e4defrag [path/to/file]
copy
Defragment a directory and everything below it
$ sudo e4defrag [path/to/directory]
copy
Check the fragmentation level without defragmenting
$ sudo e4defrag -c [path/to/file_or_device]
copy
Print verbose per-file information
$ sudo e4defrag -v [/dev/sdXN]
copy

SYNOPSIS

e4defrag [-c] [-v] target...

DESCRIPTION

e4defrag defragments an ext4 filesystem. It can operate on entire filesystems, directories, or individual files.Unlike offline defragmenters, e4defrag can run while the filesystem is mounted and in use.

PARAMETERS

-c

Check the current fragmentation state and print a fragmentation score without defragmenting. No root privileges are needed for files you own.
-v
Verbose output, printing the result for each file
target
Device, directory, or file to defragment. A device must be mounted.

INSTALL

sudo apt install e2fsprogs
copy
sudo dnf install e2fsprogs
copy
sudo pacman -S e2fsprogs
copy
sudo apk add e2fsprogs-extra
copy
sudo zypper install e2fsprogs
copy
brew install e2fsprogs
copy
nix profile install nixpkgs#e2fsprogs
copy

CAVEATS

ext4 only: the kernel's EXT4IOCMOVE_EXT ioctl is what does the work, so ext2/ext3 filesystems are rejected. The target filesystem must be mounted, since e4defrag operates online. Defragmentation needs free contiguous space, so it is largely ineffective on nearly full filesystems. Files with a fragmentation score under 30 are already considered fine and are left alone.

SEE ALSO

RESOURCES

Copied to clipboard
Kai