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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. Beginner’s Guide to LVM (Logical Volume Management)
  2. Understanding OpenSSH Configuration Files
  3. bat: command not found
  4. How to Configure rsyslog Server to Accept Logs via SSL/TLS
  5. UNIX/Linux : Access control lists (ACLs) basics
  6. CentOS / RHEL : How to configure a user account to never expire (disable password ageing)
  7. How to add additional language support in CentOS/RHEL
  8. How to Update the hostname in Shell Prompt Once it is Changed in the Linux OS
  9. mons Command Examples in Linux
  10. CentOS / RHEL 7 : How to install and configure telnet

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright