How to clear cache and temp files in Linux to speed up your system fast

4 hours ago 3
penguinfly-screenshot-2025-05-12-124527.png
Vicki Jauron, Babylon and Beyond Photography/Getty Images

Linux runs precise good connected each types of systems. It's built for velocity and proves to me, connected a regular basis, however superior it is successful presumption of velocity and reliability.

That doesn't mean it's perfect. Things hap (albeit rarely) that tin adhd to a strategy slowdown. One specified contented tin beryllium interior retention that has been utilized up. I remember, a fewer years ago, I was moving connected a Linux server that had go astir unresponsive. Turns retired a rogue exertion was dumping tons of impermanent and cache files, causing the thrust to support filling up. I had to region those files earlier I could adjacent statesman to troubleshoot the issue.

Also: My 5 go-to Linux commands for troubleshooting - and however I usage them

Although that was an anomaly, it does happen, and erstwhile it does, you'll privation to cognize however to nonstop those files into oblivion. I'm going to amusement you a fewer methods of taking attraction of the issue.

Let's dive in.

How to region cache files

Most distributions see options for helping you cleanable things up. Let's archetypal commencement with however this tin beryllium done via the built-in bundle managers.

When you usage a bundle manager, it mostly downloads bundle files to marque things easier. Those packages tin adhd up and (on uncommon occasions) origin problems. Fortunately, some apt and dnf see options for cleaning those up. 

For distributions that usage the apt bundle manager, you tin delete the cache with the command:

Show more

sudo apt clean

The supra bid removes each cached files, which see bundle downloads and repository metadata.

Also: The archetypal 5 Linux commands each caller idiosyncratic should learn

If you're utilizing a organisation that works with the dnf bundle manager, the equivalent bid is:

Show more

sudo dnf cleanable all

The supra bid does the aforesaid arsenic apt cleanable but besides refreshes the repository data.

One happening to support successful caput is that dnf updates the bundle cache automatically (when it becomes stale), truthful it's not needed arsenic often arsenic apt clean.

Deleting different caches

That takes attraction of your bundle manager cache files. But what astir different cache files? There are besides modular cache files (files that were precocious accessed and stored, truthful they don't request to beryllium queried from the hard disk) and dentry/inode cache files (directory and record attributes). 

PageCache consists of files that were precocious accessed and stored truthful they volition not request to beryllium queried from the hard disk again (unless that record changes oregon the cache is cleared to marque country for different data). Storing these files makes for little constitute interaction connected a hard drive, and besides increases the velocity astatine which files tin beryllium work from RAM.

Also: I've utilized dozens of distros arsenic a Linux powerfulness user, but this 1 feels genuinely different

Dentry and inode caches are directory and record attributes, which enactment successful conjunction with PageCache and trim disk input/output operations.

Fortunately, systemctl includes a instrumentality to wide PageCache. The bid for this is:

sudo sysctl vm.drop_caches=1

To wide dentries and inodes, usage the pursuing command:

sudo sysctl vm.drop_caches=2

To wide PageCache, dentries, and inodes, the bid is:

sudo sysctl vm.drop_caches=3

You'll besides privation to delete your web browser cache (which tin often store sizeable data). To bash that, you would spell done your web browser's paper and wide the browsing data. Or you could usage the bid enactment for this. For example, if you usage Firefox, you would contented the command:

rm -rf ~/.cache/mozilla

How to region impermanent files

Linux stores impermanent files successful a peculiar directory, /tmp. I would impulse you to usage caution erstwhile deleting these files due to the fact that peculiar files are stored successful that directory, and Linux already has mechanisms successful spot to delete those files regularly. 

Also: I'm a command-line pro and this is the champion terminal app I've ever used, acknowledgment to AI

Thanks to systemd, those temp files are ever deleted 15 minutes aft a strategy footwear (or reboot) oregon 24 hours aft the past work trigger. You tin set those values by opening the configuration record with:

sudo nano /usr/lib/systemd/system/systemd-tmpfiles-clean.timer

In that file, you'll spot the pursuing 2 lines:

OnBootSec=15min
OnUnitActiveSec=1d

You tin alteration those values to immoderate you need. If you bash marque changes, you'll request to reload the work with the pursuing 2 commands:

sudo systemctl daemon-reload
sudo systemctl alteration --now systemd-tmpfiles-clean.timer

Again, I wouldn't manually delete files from /tmp. If you judge that the folder is getting full, reboot your computer, and they'll beryllium removed aft the specified OnBootSec clip has passed.

Also: 5 Linux commands for rapidly uncovering the strategy accusation you request to know

I person manually deleted files and subfolders from /tmp earlier and recovered that everything works good afterward, but I would not urge that you bash the same.

As always, usage caution erstwhile deleting immoderate strategy record connected Linux. With impermanent files, it's champion to let the strategy to instrumentality attraction of them, and with cache files, arsenic agelong arsenic you're careful, things should beryllium OK (but inactive usage a measurement of caution).

Get the morning's apical stories successful your inbox each time with our Tech Today newsletter.

Read Entire Article