- I never go off-grid without this rugged Android phone - and it's on sale
- The Co-Op, M&S, Harrods… You? Mitigating the Risk of Ransomware - IT Governance Blog
- Have a genius business idea? These 2 AI tools can help you turn it into a reality
- Report Reveals BEC Cryptocurrency Scams Rose by 344%
- The best AirTag alternatives I've tested are just as good but half the price
How to clear cache and temp files in Linux to speed up your system fast

Linux runs very well on all types of systems. It’s built for speed and proves to me, on a daily basis, how superior it is in terms of speed and reliability.
That doesn’t mean it’s perfect. Things happen (albeit rarely) that can add to a system slowdown. One such issue can be internal storage that has been used up. I remember, a few years ago, I was working on a Linux server that had become almost unresponsive. Turns out a rogue application was dumping tons of temporary and cache files, causing the drive to keep filling up. I had to remove those files before I could even begin to troubleshoot the issue.
Also: My 5 go-to Linux commands for troubleshooting – and how I use them
Although that was an anomaly, it does happen, and when it does, you’ll want to know how to send those files into oblivion. I’m going to show you a few methods of taking care of the issue.
Let’s dive in.
How to remove cache files
Most distributions include options for helping you clean things up. Let’s first start with how this can be done via the built-in package managers.
When you use a package manager, it generally downloads package files to make things easier. Those packages can add up and (on rare occasions) cause problems. Fortunately, both apt and dnf include options for cleaning those up.
For distributions that use the apt package manager, you can delete the cache with the command:
sudo apt clean
The above command removes all cached files, which include package downloads and repository metadata.
Also: The first 5 Linux commands every new user should learn
If you’re using a distribution that works with the dnf package manager, the equivalent command is:
sudo dnf clean all
The above command does the same as apt clean but also refreshes the repository data.
One thing to keep in mind is that dnf updates the package cache automatically (when it becomes stale), so it’s not needed as frequently as apt clean.
Deleting other caches
That takes care of your package manager cache files. But what about other cache files? There are also standard cache files (files that were recently accessed and stored, so they don’t need to be queried from the hard disk) and dentry/inode cache files (directory and file attributes).
PageCache consists of files that were recently accessed and stored so they will not need to be queried from the hard disk again (unless that file changes or the cache is cleared to make room for other data). Storing these files makes for less write impact on a hard drive, and also increases the speed at which files can be read from RAM.
Also: I’ve used dozens of distros as a Linux power user, but this one feels truly different
Dentry and inode caches are directory and file attributes, which work in conjunction with PageCache and reduce disk input/output operations.
Fortunately, systemctl includes a tool to clear PageCache. The command for this is:
sudo sysctl vm.drop_caches=1
To clear dentries and inodes, use the following command:
sudo sysctl vm.drop_caches=2
To clear PageCache, dentries, and inodes, the command is:
sudo sysctl vm.drop_caches=3
You’ll also want to delete your web browser cache (which can often store considerable data). To do that, you would go through your web browser’s menu and clear the browsing data. Or you could use the command line for this. For example, if you use Firefox, you would issue the command:
rm -rf ~/.cache/mozilla
How to remove temporary files
Linux stores temporary files in a special directory, /tmp. I would urge you to use caution when deleting these files because special files are stored in that directory, and Linux already has mechanisms in place to delete those files regularly.
Also: I’m a command-line pro and this is the best terminal app I’ve ever used, thanks to AI
Thanks to systemd, those temp files are always deleted 15 minutes after a system boot (or reboot) or 24 hours after the last service trigger. You can adjust those values by opening the configuration file with:
sudo nano /usr/lib/systemd/system/systemd-tmpfiles-clean.timer
In that file, you’ll see the following two lines:
OnBootSec=15min
OnUnitActiveSec=1d
You can change those values to whatever you need. If you do make changes, you’ll need to reload the service with the following two commands:
sudo systemctl daemon-reload
sudo systemctl enable –now systemd-tmpfiles-clean.timer
Again, I wouldn’t manually delete files from /tmp. If you believe that the folder is getting full, reboot your computer, and they’ll be removed after the specified OnBootSec time has passed.
Also: 5 Linux commands for quickly finding the system information you need to know
I have manually deleted files and subfolders from /tmp before and found that everything works fine afterward, but I would not recommend that you do the same.
As always, use caution when deleting any system file on Linux. With temporary files, it’s best to allow the system to take care of them, and with cache files, as long as you’re careful, things should be OK (but still use a measure of caution).
Get the morning’s top stories in your inbox each day with our Tech Today newsletter.