filefrag - Linux
Overview
filefrag is a powerful command-line utility that analyzes file fragmentation on ext2/3/4 file systems. It provides detailed information about the extent and distribution of fragmentation, helping system administrators and users optimize disk performance.
Syntax
filefrag [options] [FILESYSTEM]
Options/Flags
- -v, –verbose: Enable verbose output, displaying additional information.
- -s, –summary: Display only a summary of fragmentation statistics.
- -p, –plot: Generate a histogram plot of fragmentation data.
- -l, –long: Display all file details, including extent information.
- -a, –all: Analyze all files, regardless of size or access time.
Examples
Analyze fragmentation of a specific file system:
filefrag /dev/sda1
Display only a summary of fragmentation statistics:
filefrag -s /dev/sda1
Generate a histogram plot of fragmentation data:
filefrag -p /dev/sda1
Display all file details, including extent information:
filefrag -l /dev/sda1
Common Issues
- Missing filesystem argument: Ensure to specify a valid filesystem path as the first argument.
- Insufficient disk space: The plot option (-p) requires sufficient free disk space.
- Unsupported filesystem: filefrag only supports ext2, ext3, and ext4 filesystems.
Integration
- Combine with find: Identify fragmented files using
find -exec filefrag {} \;
. - Create scripts: Automate fragmentation analysis and reporting tasks.
- Use in performance optimization tools: Integrate filefrag into scripts to monitor and troubleshoot file system performance.
Related Commands
- df: Display disk usage statistics.
- fsck: Check and repair file systems.
- e2fsck: Specific file system checker for ext2/3/4 filesystems.