• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

fstrim Command Examples in Linux

by Deepika

fstrim is a command-line utility that is used to discard (or “trim”) unused blocks on a mounted file system. It is commonly used to reclaim space on solid-state drives (SSDs) and other types of flash-based storage devices. When a file is deleted on a file system, the space it occupied is not immediately reclaimed. Instead, the file system marks the space as available for reuse, but the data remains on the storage device until it is overwritten by new data. This can cause the storage device to become fragmented over time, resulting in reduced performance.

fstrim works by examining the file system to identify blocks that are no longer in use and sending a TRIM command to the storage device to discard them. This allows the storage device to reclaim the space and improves its performance by reducing fragmentation. The fstrim command can be used on a mounted file system, it can be scheduled to run on a regular basis using cron, systemd timer or other scheduling tools. The command can also be used with options to specify the file system path or the specific device that needs to be trimmed.

It is important to note that, fstrim command works only on file systems that support the TRIM command such as ext4, btrfs, f2fs and other modern file systems, it will not work on older file systems like ext3, NTFS, etc.

fstrim Command Examples

1. Trim unused blocks on all mounted partitions that support it:

# sudo fstrim --all

2. Trim unused blocks on a specified partition:

# sudo fstrim /

3. Display statistics after trimming:

# sudo fstrim --verbose /

Filed Under: Linux

Some more articles you might also be interested in …

  1. awk Command Examples in Linux
  2. What are Shell Scripts? How to Create Shell Scripts?
  3. perf Command Examples in Linux
  4. grpck command – Remove corrupt or duplicate entries in the /etc/group and /etc/gshadow files.
  5. setsid Command Examples in Linux
  6. How to Limit/throttle rsync transfer speed in Linux
  7. just Command Examples
  8. Working with Vim editor (Text Editor)
  9. lzip Command Examples
  10. edquota: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright