$linuxjunkies
>

fstrim(8)

Discard unused blocks on mounted filesystems to optimize SSD performance and reclaim space.

UbuntuDebianFedoraArch

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

FlagWhat it does
-v, --verbosePrint the number of bytes discarded for each filesystem
-q, --quietSuppress output; exit status only
-l, --lowerbound=SIZEDiscard only extents larger than SIZE bytes (default 0)
-m, --minimum=SIZEDiscard only contiguous extents larger than SIZE bytes
-o, --offset=OFFSETByte offset where to start discarding in the filesystem
-n, --no-model-checkRun even if device is not recognized as supporting TRIM
-a, --allTrim all mounted filesystems on devices that support TRIM
--dry-runShow 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 /var

Automatically TRIM all mounted filesystems that support it

fstrim -a

Only 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.timer

Preview how many blocks would be discarded without actually trimming

fstrim --dry-run /

Related commands