Often you may need to free up disk space on your Linux system to make your programs and processes run faster, and avoid problems of running out of disk space. In this article, we will look at several useful ways to clean up disk space in Linux. There is no single command or readymade tool to help you free up disk space. It is a combination of commands that will help you identify and clean up your disk.
How to Clean Up Disk Space in Linux
Here are the steps to clean up disk space in Linux. You can use these steps on almost all distributions.
1. Delete Big files
The most basic strategy is to identify and delete any unnecessary files that consume lot of space. Here is how to go about it. Go to root folder.
$ cd /
List folders by size.
$ sudo du -h --max-depth=1
Note biggest directories. cd into any of the big directories
Run ls -l command to list all its files and folders. Delete the ones you don’t need.
Repeat these steps for other folders listed in the output of du command above.
2. Remove unnecessary packages
You can remove unnecessary packages from your system with the following command. It will automatically remove unused packages from your system.
$ sudo apt-get autoremove
3. Remove unnecessary applications
$ sudo apt-get remove
4. Clean up apt-cache in Ubuntu
If you are using Ubuntu/Debian system, then you should note that apt-get command uses a cache of previously downloaded & installed packages on your system. It is located at /var/apt/cache and grows over time as you install/update more and more packages on your system. Run the following command to clear it.
$ sudo du -sh /var/cache/apt
You may also use any of the following commands to accomplish the same.
$ sudo apt-get autoclean OR $ sudo apt-get clean
5. Clean up System Logs
Every Linux system logs different kinds of information such as system messages, standard output and errors of various services in Ubuntu. Over time, these logs grow as your system activity increase and take up a lot of space if left unchecked. Here is the command to view the size of your system log.
$ sudo journalctl --disk-usage
Here is the command to restrict your system to log only information for up to past 3 days. You may change the timeframe as your requirement by modifying ‘3d’ in the following command.
$ sudo journalctl --vacuum-time=3d
In this article, we have looked at different ways to clean up disk space in Linux. As mentioned earlier, you will need to free up space, part by part, using a set of commands. There is not single command or tool that automatically identifies all unused programs, files and applications and deletes them. The above list is not exhaustive but it will help you free up substantial amount of disk space quickly.
- How to List Installed Packages on Ubuntu 22.04
- How to Make Ubuntu Terminal Look like Kali Linux
- How To Docker Create Container, Change Container, Save as new image, and Connect to Container Step-By-Step PLUS much more
- Sharing Files between RHEL 6 and Windows Systems with Samba
- How to Grow XFS Filesystem in RHEL 7
How to Add Response Header in NGINX
How to Redirect Parent Folder in Apache
How to List Open Ports in Linux
How to Rewrite URL to Subdirectory in Apache
How to Rewrite URL with Parameters in Apache
— Update: 27-01-2023 — us.suanoncolosence.com found an additional article Essential Guide: 5 Simple Ways To Free Up Space on Ubuntu from the website www.omgubuntu.co.uk for the keyword how to clean linux disk space.
Let’s say you need to free up space on Ubuntu — how do you go about it?
Unlike Windows, which comes with built-in defrag and disk clean-up tools, Ubuntu doesn’t make itimmediatelyobvious how you go abouttrying to free up space.
So what do you do once you’ve emptied the trash and deleted those sizeable .ISO downloads? How do you recover more space?
Below, we show you 5 super simple(and in some cases blindingly obvious yet easily forgotten) stepsyou cantake to get back GBs, materialise MBs, and clean out the KB cruft!
Next time you need more space — and heck: even ifyoudon’t —here are 5 simple waysto free up disk space on Ubuntu.
1.Clean the APTCache (And Do It Regularly)
It sounds so obvious yet chances are you haven’t done this for a while.
Bydefault Ubuntu keeps everyupdate it downloads andinstalls in a cache on your disk, just in case you need it again.
This isuseful if you regularly add and remove apps, find yourself needing to reconfigure/reinstall a specific package, or simply have a poor connection.
But the flip side is that the aptpackage cache can quickly swell to several hundred MBs. This command tells youhow big your apt cache is:
du -sh /var/cache/apt/archives
To clean the apt cache on Ubuntu simply runthe followingcommand.
sudo apt-get clean
The apt clean command removes ALL packages kept inthe apt cache, regardless of age or need. If you’re on a slow, capped or intermittent connection you may want to consider skipping this step.
2. Remove OldKernels (If No Longer Required)
Now, admittedly, thisstep is one you want to approach withcaution.
Having a choice of kernels to boot up is, honestly, quite handy, especially if you noticesomething has gone awry while usingthe latest one.
Unless you’re in the throes of constant hardware woes there’s little needto hoard kernels.
It’s easy to remove old kernels in Ubuntu.You can do itfrom the command line using the followingcommand:
sudo apt-get autoremove --purge
Note that this command will onlyremove kernels that a) are no longer needed and b) wereinstalled from the Ubuntu archive throughsystem updates. If you install kernels manually or using a third-party PPA you’ll need to roll up your sleeves and remove those manually.
3. Uninstall Apps & Games You Never Use (And Be Honest!)
Chances are you have a number ofapps installed that you neveruse. Maybe you installed them on theback of an awesomereview, out of nosiness, or to tackle a specific task.
Whatever the excuse,if you no longer need an app, and it’s taking up space, don’t be afraid touninstall it.
Typical apps you may wish to expunge include web browsers (are you ever going to use Opera, Epiphany, Midori and Min?), music players (heck knows there’s enough of ’em) and games that sounded good in the Steam Store blurb but were as much fun as aWindows 10 update combo!
- Determining cause of Linux kernel panic
- How to deploy an Apache web server quickly
- How To Install Magento on Ubuntu 20.04 LTS
- Bashrc vs. bash_profile: What Is the Difference?
- Linux cksum command explained for beginners (with examples)
And everyone hasLibreOffce Draw knocking about doing nothing! 😅
Don’t lie to yourself about might-needs and could-dos, either. The beauty of most software is that it’s not going away anytime soon. This is never truer than on Linux, where apps remain anapt install command away.
To remove apps from the command line run:
sudo apt-get remove package-name1 package-name2
Toremove excess packages anddependencies that are no longer required (because you’ve uninstalled other packages or newer versions have replaced them) run the following command:
sudo apt-get autoremove
4. Use A System Cleaner like BleachBit
Writing a “to-do” list on system cleaning would end up 10x longer ifwe listed every app, cache, log and system process hiding in every nook and cranny of your OS.
BleachBitsaves us from doing that.
It’s like CCleaner for Linux; abyte scouringbeast. The app can find and clean pretty much every fluff file there is and, as a result, should only ever be used with caution.
BleachBut can wipe the caches of more than 70 popular desktopapplications (including most web browsers); hoover upold file, browser and bash histories; and makes light work of those crash logs you’ll never get around to reading.
No surprise that we recommend installing it as one of our top things to do after installing Ubuntu.
You can install BleachBit on Ubuntu 16.04 LTS (and above) straight from Ubuntu Software.
Run the app as root for maximum cleaning power. Check the boxes beside the things you’d like to clean. Click Previewto see an estimate of how much space they currently take up, and click Cleanto remove them.
Install BleachBit from Ubuntu Software
5. Stay up to date (seriously, do it!)
The most obvious step on this list is also the one few people would think to recommend. See, unlike Windows, where every new update adds more overhead and bloat, package updates on Linux oftenfreethan use it.
So next time you put off that 156MB librandom-package102 update cos you’re running low on space, maybe think again!
That just about covers it. If you only remember two steps from this listmake it the first and last.
- Clean your apt cache from time-to-time
- Install patches, updates, and fixes
Now go forth and free space!
Let us know how much space you manage to claw back or share your own top space-saving tips in the comments!
How do I clear free disk space in Linux? ›
Removing files and formatting disks is a common task for users. And Linux provides a number of utilities to delete files and folders from the command line. The most common command to delete files and folders is rm and rmdir , respectively.How do I free up disk space in Unix? ›
- Delete backup and temporary files.
- Store temporary files elsewhere.
- Compress files.
- Store unused files elsewhere.
- Clean the APT Cache (And Do It Regularly) ...
- Remove Old Kernels (If No Longer Required) ...
- Uninstall Apps & Games You Never Use (And Be Honest!)
A clean command is usually included in Linux package managers which can be used to clear the package manager's cache. It is also a good command to use if package-related issues are being generated because of corrupted metadata. Use the below command for Debian and Ubuntu. # sudo apt clean.How to check free space in Linux? ›
That command is df -H. The -H switch is for human-readable format. The output of df -H will report how much space is used, available, percentage used, and the mount point of every disk attached to your system (Figure 1).How do I clear all disk space? ›
- Uninstall unnecessary apps and programs. ...
- Clean your desktop. ...
- Get rid of monster files. ...
- Use the Disk Cleanup Tool. ...
- Discard temporary files. ...
- Deal with downloads. ...
- Save to the cloud. ...
- Maintenance is vital.
- Update Windows 10. ...
- Disable Superfetch. ...
- Remove viruses and malware. ...
- Reinstall or update your antivirus software. ...
- Close background applications. ...
- Reset or reinstall synchronization tools. ...
- Rebuild the Windows Search index. ...
- Repair hard disk issues.
One of the easiest ways to clean up files you no longer need is by using Disk Cleanup. Open Disk Cleanup by clicking the Start button . In the search box, type Disk Cleanup, and then, in the list of results, select Disk Cleanup. If prompted, select the drive that you want to clean up, and then select OK.How do I fix 100 disk usage in Linux? ›
- Compress uncompressed log and other files using gzip or bzip2 or tar command: ...
- Delete unwanted files using rm command on a Unix-like system: ...
- Move files to other system or external hard disk using rsync command:
It should not hang the system; however, applications will fail when they try to write to files and log files might not get updated.
How do I find out what folder is taking up more space in Linux? ›
- Open the terminal application.
- Login as root user using the sudo -i command.
- Type du -a /dir/ | sort -n -r | head -n 20.
- du will estimate file space usage.
- sort will sort out the output of du command.
- We can clean the temporary files using the command ” sudo apt-get autoremove “.
- Open the terminal type the command sudo apt-get autoremove.
- You will be prompted to enter your password and then hit enter.
- You are done. Temporary files are deleted.
The sudo apt-get update command is used to download package information from all configured sources. The sources often defined in the /etc/apt/sources. list file and other files located in /etc/apt/sources. list.What is clean disk command? ›
When you have an entire disk to wipe clean, you can use the diskpart clean command to convert all the stored data into unallocated space. This operation deletes all data on the disk by writing zeros on each disk sector. Diskpart also removes all partition and volume information from the selected drive.What is the cleanup command? ›
The cleanup command deletes the temporary files created during a cycle of refinement. If you interrupt a refinement run the simplest way to get ready to restart refinement is this command.How do I run a clean command? ›
- Click Start, and then click Run.
- In the Open box, type the following command, and then press Enter: c:\windows\SYSTEM32\cleanmgr.exe /dDrive Note In this command, the placeholder Drive represents the drive letter of the hard disk to be cleaned.
The command used in this method uses the "echo 3 >" which cleans the PageCache, dentries, and inodes at the same time. Command: # sync ; echo 3 > / porc / sys / vm / drop_caches.How do I completely clear a disk? ›
- Open the Start menu and select Settings.
- Choose the System category from the menu on the left, then scroll down and select Recovery.
- Click Reset PC.
- Select Remove everything.
- Choose how you'd like to reinstall Windows, then click Change settings.
- Switch the Clean data?
Click Start, and then click Run. In the Open box, type the following command, and then press Enter: c:\windows\SYSTEM32\cleanmgr.exe /dDrive Note In this command, the placeholder Drive represents the drive letter of the hard disk to be cleaned.What is taking up 100% of my disk space? ›
Running lots of applications at once may cause 100% disk usage in Windows 10. Uninstalling these programs often isn't possible, because you may need them. Manually pausing the background apps is only a short-term solution, as many will restart upon bootup or run quietly in the background.
Why is my disk space so full? ›
For many computer users, most of the disk space used is by applications and games. If you find that you no longer use certain programs, you can uninstall and remove them from your hard drive. Again, Windows provides the ability to easily get rid of any unwanted programs that we may have on our computer.Why do I have 100% disk space? ›
100% disk usage means that your disk has reached its maximum capacity i.e. it is fully occupied by some or the other task. Every hard-disk has specific read/write speed and generally the sum of the read/write speed is 100mbps to 150mbps.Is it safe to delete cache files on Linux? ›
Unlike /var/spool , the cached files can be deleted without data loss. The data must remain valid between invocations of the application and rebooting the system. Files located under /var/cache may be expired in an application specific manner, by the system administrator, or both.Is it good to clear cache in Linux? ›
Thus, in case, Linux discovers any resource in the cache, your request can not reach the disk. So, cleaning the buffer and cache will enable your operating system to look for the resource on the disk as the disk cache becomes less beneficial.