How to Manage Disk Space on Linux

How to Manage Disk Space on Linux Like a Pro (CLI Only)

If you click our links and make a purchase, we may earn an affiliate commission. Learn more

Has your Linux system frozen unexpectedly or refused to update or install because you ran out of space? It’s happened to me several times, trying to figure out what’s safe to delete and what’s not. It can be a mess sometimes, but the good news is that it’s easy to solve once you know where to look and what to use.

Disk space on Linux can be managed effectively using commands like df, du, and ncdu, combined with regular cleanup of system logs, cache files, and unused packages. Additional storage can be added using external drives or cloud-based mounting solutions.

You don’t need hours of free time to mess around with your disks; you need a few handy commands and a bit of routine. Let’s review each step together and get your system running smoothly again.

If you need help with Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your system. Click here to get it for free!

Start by Checking What’s Taking Space (df and du)

The first step before actually managing your disk is to get information from it; otherwise, how would we know what we’re doing? The most vital information you’ll need to know is the size of your disk, how it’s partitioned, and how much space is used.

First, you will need to get an overview of your system’s partitions and their usage, so you can use:
df -h

This displays disk usage in human-readable format (-h), showing total size, used space, and available space per mounted partition.

Now that you know which partitions are nearly full, let’s check which folders or files are the biggest takers. To do that, use:
du -h / | sort -hr | head -n 20

This command shows the largest directories starting from the root (/). You can use it inside any folder if you want to be more specific.

As you can see, there are commands like this that can become very long, and in our case, typing them constantly or remembering them can be a hassle. For those cases, it is quite useful to use aliases and maybe even for other long commands you have in mind.

Always Forgetting Linux Commands?
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.

Download now

Identify and Delete Big or Non-Important Files (ncdu)

You already have a sense of what’s taking space, but what if you need something more interactive and visual than du? That’s where ncdu comes in. The ncdu command is like a graphical version of du that you can still use in the terminal.

Prefer reading without ads and popups?
Members get an ad-free version of every guide, plus exclusive project support.
Join the Community | Sign In

To install it:
sudo apt install ncdu
(Debian/Ubuntu)
sudo pacman -S ncdu
(Arch)
sudo dnf install ncdu
(Fedora)

You simply have to use the command:
sudo ncdu

You’ll see a descending list of the heaviest files and folders, displayed in percentage format. Not only that, but you can even delete files directly from this interface by selecting them and pressing d. It’s perfect for spotting forgotten files, backups or junk downloads that are eating your space.

Like this command, many underrated or little-known commands are incredible tools in everyday life. Do not be afraid to learn more commands that you do not know!

Tip: Command lines can be a pain to memorize. I put the essential Linux commands on a printable cheat sheet so you don't have to keep googling them. You can grab the PDF here if you want to save some time.

Clean Up Junk Files and System Bloat (apt, logs, temp files)

Now, you already know what takes up space, but among so many files, which one is really safe to delete that is not important for the system? There are junk files or system bloat that you can safely delete.

First, let’s start by using APT’s commands to handle this automatically:
sudo apt autoremove -y
sudo apt clean

These commands remove unused packages and cached data. If you’re using a different package manager (like dnf or pacman), you can use their equivalent cleanup tools.

Next, let’s focus on something simple, but that in the long run can cover large spaces in your system storage… the logs. You may not notice any relevant space used at first, but that’s because logs accumulate over time as you use the device.

Always Forgetting Linux Commands?
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.

Download now

You can limit the amount and size of logs that can be saved on /var/log (otherwise it could even take up several gigabytes) using the journalctl command:
sudo journalctl --vacuum-size=100M

This will reduce systemd logs to 100MB. You can also clean old log files manually:
sudo rm /var/log/.gz
sudo rm /var/log/.[0-9]

Other temporary files are worth checking inside the following paths:

  • /tmp/
  • /var/tmp
  • /var/cache
  • Browser or application caches (~/.cache/)

Some apps (like web browsers or package managers) may have built-in tools or settings to delete cache as well.

Bonus: Hidden Spots That Waste Space (Trash, Caches, Temp)

You already deleted a lot of useless or unimportant files that occupied space, but is there more? With time and experience, I have discovered that there are hidden places where files are stored that take up a lot of storage.

Here are a few sneaky places where space-wasters might hang out:

  • ~/.local/share/Trash/ – This is where files go when you “delete” them from the GUI. They’re not gone until you empty the trash.
  • ~/.cache/ – Application cache, safe to delete most of the time.
  • /var/tmp/ – Temporary files that persist longer than /tmp/.
  • Flatpak apps: ~/.var/app/ – Some Flatpak applications store data here.
  • Docker images/volumes: docker system prune – If you use containers, this clears unused data.

Each one contains temporary files that, over time, will occupy more and more space, so it is something useful to know. It will save you headaches when managing your storage.

Create a Routine or Automate Cleanup Tasks

Cleaning up once is great, but doing it without effort is even better. The good news? You can automate most of the steps we’ve covered to keep your system clean.

Always Forgetting Linux Commands?
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.

Download now

Here’s how you can create a simple script:

#!/bin/bash
sudo apt autoremove -y
sudo apt clean
sudo journalctl --vacuum-size=100M
rm -rf ~/.cache/*
rm -rf ~/.local/share/Trash/*

Save this as cleanup.sh, and make it executable:
chmod +x cleanup.sh

And schedule it to run weekly with crontab:
crontab -e

This will run the script every Sunday at 3 AM.

Note: You can choose to include the folders from previous sections, but beware! Not every temporal file should be deleted; some of them are important depending on their usage.

And you will surely notice that many different commands or commands that are not very common in your day-to-day life or knowledge. Learning Linux is a long journey, but with guides like our Master Linux Command, you can easily learn all the necessary commands in Linux.


🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Prefer videos over reading? The RaspberryTips Community members get exclusive video lessons every month. Join now and watch them all right away. Get instant access.

Expand Storage: Physical Drives or Cloud Mounts

Sometimes, cleaning isn’t enough, especially on systems with small SSDs or embedded boards like Raspberry Pi. For those cases, it is necessary to scale up your storage.

Add a Physical Drive (HDD, SSD, or USB Stick)

One easy way to add space is with physical devices, like a USB stick for backups or a large HDD for extra storage.

You can check if the new drive is recognized with:
lsblk

Always Forgetting Linux Commands?
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.

Download now

Then, mount it manually using mount or set it up to auto-mount by editing /etc/fstab. This way, you can access it every time you boot up.

Use Cloud or Remote Storage

If you don’t want to deal with cables or physical devices, cloud storage is a great alternative. It’s surprisingly fast and easy.

One way to add cloud storage is by using rclone to mount services like Google Drive, Dropbox or even S3 buckets directly into your file system.

Another great option is to mount remote servers over SSH using sshf:

sudo apt install sshfs
mkdir ~/remote_server
sshfs user@address:/path/to/folder ~/remote_server

You can even use NFS or Samba for local network shares.

Cloud and remote storage are perfect for saving large files, backups, or shared projects.

Related: Top 25 Raspberry Pi Tips and Tricks You’ll Actually Use

Managing disk space on Linux can be a tedious task when your system freezes or you see “disk full” errors. However, a little routine with the right tools like ncdu, df, du or even with cron can make the job easier. It is always better to clean smarter, not harder.

Whenever you're ready, here are other ways I can help you:

Master Linux Commands: Overwhelmed with Linux commands? This book is your essential guide to mastering the terminal. It includes practical tips, real-world examples, and a bonus cheat sheet to keep by your side.

The RaspberryTips Community: Need help with Linux or want to chat with people who actually get it? Join the RaspberryTips Community and get access to private forums, exclusive lessons, and direct support.

You can also find all my recommendations for tools and hardware on this page.

Similar Posts