fstrim(8)
Discard unused blocks on mounted filesystems to optimize SSD performance and reclaim space.
Synopsis
fstrim [OPTION]... MOUNTPOINT...Description
fstrim issues TRIM or DISCARD commands to the underlying block device for mounted filesystems. TRIM tells SSDs which blocks are no longer in use, allowing the drive to optimize performance and wear leveling. It can also reclaim space on virtual disks and thin-provisioned storage.
By default, fstrim operates in verbose mode and reports the number of bytes discarded. It is commonly run periodically via cron or systemd timers, though many modern systems enable automatic TRIM with the discard mount option.
Common options
| Flag | What it does |
|---|---|
-v, --verbose | Print the number of bytes discarded for each filesystem |
-q, --quiet | Suppress output; exit status only |
-l, --lowerbound=SIZE | Discard only extents larger than SIZE bytes (default 0) |
-m, --minimum=SIZE | Discard only contiguous extents larger than SIZE bytes |
-o, --offset=OFFSET | Byte offset where to start discarding in the filesystem |
-n, --no-model-check | Run even if device is not recognized as supporting TRIM |
-a, --all | Trim all mounted filesystems on devices that support TRIM |
--dry-run | Show what would be discarded without actually trimming |
Examples
Discard unused blocks on the root filesystem and report bytes freed
fstrim -v /TRIM multiple mounted filesystems in one command
fstrim -v /home /varAutomatically TRIM all mounted filesystems that support it
fstrim -aOnly discard contiguous extents larger than 1 GB to reduce I/O overhead
fstrim -v -m 1G /Run silently and execute a command only on success
fstrim -q /mnt/ssd && echo 'TRIM complete'Enable the weekly TRIM timer on systemd systems
sudo systemctl start fstrim.timerPreview how many blocks would be discarded without actually trimming
fstrim --dry-run /