How to Clean Up Disk Space in Linux (2023)

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.

(Video) How to clear unwanted disk space | Linux Server Disk Capacity shows 100% full

$ 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.

Also read:

    Read also:

  • 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 — found an additional article Essential Guide: 5 Simple Ways To Free Up Space on Ubuntu from the website 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.

(Video) How to Check Linux Disk Space | Linux DF and DU Commands | How to Clear Space | Linux Tutorials

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.

(Video) 014 - How To Cleanup Ubuntu Linux And Free Up Disk Space

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!

    Read also:

  • 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.

(Video) How To Free Up Space In Ubuntu and other Linux distributions

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.

  1. Clean your apt cache from time-to-time
  2. 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!

  • Tweet
  • Post
  • Share
  • Send


(Video) Kali Linux How to Clean System and Free Disk Space | EthicaCyber


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? ›

Make better use of your disk space in Unix
  1. Delete backup and temporary files.
  2. Store temporary files elsewhere.
  3. Compress files.
  4. Store unused files elsewhere.
Sep 20, 2021

How do I free up disk space on Ubuntu? ›

Next time you need more space — and heck: even if you don't — here are 5 simple ways to free up disk space on Ubuntu.
  1. Clean the APT Cache (And Do It Regularly) ...
  2. Remove Old Kernels (If No Longer Required) ...
  3. Uninstall Apps & Games You Never Use (And Be Honest!)
Dec 9, 2021

What is clean command in Linux? ›

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? ›

Here's how to clear disk space and increase storage on your desktop or laptop, even if you've never done it before.
  1. Uninstall unnecessary apps and programs. ...
  2. Clean your desktop. ...
  3. Get rid of monster files. ...
  4. Use the Disk Cleanup Tool. ...
  5. Discard temporary files. ...
  6. Deal with downloads. ...
  7. Save to the cloud. ...
  8. Maintenance is vital.
Apr 4, 2022

How do I get rid of 100% disk space? ›

The 12 best ways to fix 100% disk usage in Windows 10
  1. Update Windows 10. ...
  2. Disable Superfetch. ...
  3. Remove viruses and malware. ...
  4. Reinstall or update your antivirus software. ...
  5. Close background applications. ...
  6. Reset or reinstall synchronization tools. ...
  7. Rebuild the Windows Search index. ...
  8. Repair hard disk issues.
Sep 26, 2022

How do I clear disk space quickly? ›

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? ›

Fixing problem when the disk is full
  1. Compress uncompressed log and other files using gzip or bzip2 or tar command: ...
  2. Delete unwanted files using rm command on a Unix-like system: ...
  3. Move files to other system or external hard disk using rsync command:
Sep 7, 2022

What happens if disk space is full in Linux? ›

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? ›

The procedure to find largest files including directories in Linux is as follows:
  1. Open the terminal application.
  2. Login as root user using the sudo -i command.
  3. Type du -a /dir/ | sort -n -r | head -n 20.
  4. du will estimate file space usage.
  5. sort will sort out the output of du command.
Mar 27, 2022

How to delete temp files in Linux? ›

Method 1 :
  1. We can clean the temporary files using the command ” sudo apt-get autoremove “.
  2. Open the terminal type the command sudo apt-get autoremove.
  3. You will be prompted to enter your password and then hit enter.
  4. You are done. Temporary files are deleted.
Jun 23, 2021

What does sudo apt update do? ›

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? ›

More Information
  1. Click Start, and then click Run.
  2. 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.

How do I clear cache in Linux terminal? ›

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? ›

Reset your PC
  1. Open the Start menu and select Settings.
  2. Choose the System category from the menu on the left, then scroll down and select Recovery.
  3. Click Reset PC.
  4. Select Remove everything.
  5. Choose how you'd like to reinstall Windows, then click Change settings.
  6. Switch the Clean data?
Jan 27, 2022

What is the command for disk clean? ›

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.


1. 032 - How To Cleanup Unwanted Dependencies, Broken Libraries And Old Kernels | Ubuntu | Red Hat
2. How to Clean Up Linux | Free Hard Disk Space in Linux with Stacer
(Comm Tech Engineer)
3. How to Clear Cache and Swap Space in Ubuntu/Linux
4. How To Free Up Disk Space On Linux Mint
5. How to clear RAM Memory Cache, Buffer and Swap Space on Linux
6. Two Easy Ways To Free Up Disk Space In Linux Mint
Top Articles
Latest Posts
Article information

Author: Domingo Moore

Last Updated: 02/23/2023

Views: 5506

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Domingo Moore

Birthday: 1997-05-20

Address: 6485 Kohler Route, Antonioton, VT 77375-0299

Phone: +3213869077934

Job: Sales Analyst

Hobby: Kayaking, Roller skating, Cabaret, Rugby, Homebrewing, Creative writing, amateur radio

Introduction: My name is Domingo Moore, I am a attractive, gorgeous, funny, jolly, spotless, nice, fantastic person who loves writing and wants to share my knowledge and understanding with you.