e4defrag - Linux


e4defrag is a powerful tool used to optimize the performance of ext4 file systems by defragmenting files and directories, reducing fragmentation and improving read/write performance. It operates on both regular files and directories, consolidating their data blocks for optimal access and utilization.


e4defrag [-v|--verbose] [-f|--force] [-b|--batch] [-i|--interval] [--max-block-count] [--min-file-size] [--target-fragmentation] [--enable-compression] [--disable-compression] [--append-only] <file-systems>


  • -v, –verbose: Enables verbose mode, providing detailed progress information during the defragmentation process.
  • -f, –force: Forces defragmentation even on file systems that are mounted read-only. Use with caution!
  • -b, –batch: Defragments multiple file systems in batch mode, without user interaction.
  • -i, –interval: Specifies the interval (in seconds) between defragmentation passes. Default: 30 seconds.
  • –max-block-count: Sets the maximum number of blocks to defragment in a single pass. Default: 1,000 blocks.
  • –min-file-size: Ignores files smaller than the specified minimum size. Default: 10 MB.
  • –target-fragmentation: Sets the target fragmentation percentage for file system optimization. Default: 5%.
  • –enable-compression: Enables data compression during defragmentation for improved storage efficiency. Note: Some file systems may not support compression.
  • –disable-compression: Disables data compression, preserving the original file sizes.
  • –append-only: Defragments only append-only files, leaving other files untouched.


  • Simple defragmentation: e4defrag /dev/sda1
  • Verbose mode with batch processing: e4defrag -vb /dev/sda1 /dev/sdb1
  • Customizable interval: e4defrag -i 60 /dev/sda1
  • Force defragmentation on a read-only file system: e4defrag -f /dev/sda1

Common Issues

  • Permission denied: Ensure you have administrative privileges to defragment file systems.
  • File system is in use: Unmount the file system before defragmentation or use the --force option cautiously.
  • Insufficient space: Check if there’s enough free space on the file system to accommodate defragmentation.
  • File system is full: Fragmentation cannot be optimized if the file system is close to capacity. Consider expanding or cleaning up the file system before defragmentation.


  • cron jobs: Schedule regular defragmentation using cron for optimal performance.
  • File system mount options: Enable periodic defragmentation automatically using the defrag mount option.

Related Commands

  • mkfs.ext4: Creates an ext4 file system.
  • tune2fs: Tunes and modifies ext4 file system parameters.
  • fsck.ext4: Checks and repairs ext4 file systems.