How to Manually Force an Ubuntu ‘TRIM’ Operation (Optimize SSD Speed)

Unlike old mechanical hard drives, modern Solid State Drives (SSDs) suffer from a unique phenomenon: when you delete a file in Ubuntu, the operating system doesn’t immediately tell the physical SSD controller that those memory blocks are free. As the drive fills up with undeleted “ghost” data, the SSD controller struggles to find empty blocks to write new files, resulting in a massive, noticeable slowdown in your overall system speed.

To fix this, Linux relies on a command called TRIM (usually via the fstrim utility). TRIM explicitly tells the SSD controller to physically wipe all the blocks containing deleted files. While Ubuntu runs an automated TRIM job once a week in the background, if you have just deleted hundreds of gigabytes of videos or uninstalled a massive game, you shouldn’t wait days for the scheduler to trigger. You should manually force the SSD to optimize itself instantly.

How to Manually Force an Ubuntu TRIM Operation

You must use the fstrim command in the terminal to instruct the SSD controller to wipe the discarded blocks.

  1. Open your Terminal application (Ctrl + Alt + T).
  2. Type the following command carefully. The -a flag tells the system to trim all mounted filesystems, and the -v flag requests verbose output so you can see exactly how much space was cleared: sudo fstrim -av
  3. Press Enter. Type your administrator password when prompted and press Enter again.
  4. The terminal will pause. The actual physical hardware on your SSD is now aggressively wiping the ghost data. Depending on how much garbage data existed, this could take anywhere from 2 seconds to 3 minutes. Do not interrupt it.
  5. Once the operation is complete, the terminal will output exactly how many gigabytes were trimmed (for example: /: 45.2 GiB (48530493440 bytes) trimmed).

Your physical SSD hardware is now completely synchronized with your Ubuntu filesystem. Because the SSD controller now knows exactly which blocks are free, writing new files will be significantly faster, restoring your computer to its peak performance.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.