Delete Large Files in Ubuntu if Your System Running Out of Space

If you’ve been using Ubuntu for a while, you might notice your system running out of space. This is normal, especially if you download a lot of files or work with big programs. But don’t worry, there’s an easy way to find and delete large files that are taking up lots of space. In this blog post, I’ll show you how to do it step by step, using simple commands. Let’s jump right in:

Why Should You Delete Large Files?

When your computer runs low on space, it can slow down. Programs might freeze, and updates won’t install properly. By deleting large, unnecessary files, you can free up space and make your system run smoother. So, this the answer why should you delete large files from your Ubuntu machine.

Step 1: Open Your Terminal

The easiest way to find and delete large files is by using your Ubuntu terminal. Don’t let that scare you, it’s not as tricky as it sounds. The terminal is like a direct line to your computer, and once you get the hang of it, you’ll see it’s pretty handy. If you want to learn about Ubuntu commands then our website if perfect for you, we have published lots of posts on command and terminal. Follow the first step now-

To open the terminal:

  1. Press Ctrl + Alt + T on your keyboard.
  2. A black window should pop up. This is your terminal.

See? Easy, right?

Step 2: Find Large Files Using the “du” Command

Now that you’ve got your terminal open, it’s time to search for those space-eating files. Ubuntu has a built-in command called du, which stands for “disk usage.” It shows you how much space files and folders are using.

How simple is that? If you get all the details related to your disk space by just using a simple command? Okay, let’s see now-

Here’s a simple command to find large files:

sudo du -ah / 2>/dev/null | grep '[0-9\.]\+G'

Let me break that down for you:

  • sudo: This gives you superuser (admin) access.
  • du -ah /: This tells Ubuntu to check the entire system for files and folders, showing their sizes in a readable format.
  • 2>/dev/null: This hides any error messages you don’t need to see.
  • grep ‘[0-9.]+G’: This filters out the results to only show files that are larger than 1GB.

Once you hit enter, Ubuntu will list all the files bigger than 1GB.

Example:

Let’s say you see something like this in the results:

1.2G /var/log/syslog
2.3G /home/user/Downloads/movie.mkv

That means there’s a 1.2GB file in the /var/log/ folder and a 2.3GB movie in your Downloads.

Got it now or have any doubts?

Step 3: Delete Large Files

Now that you’ve found the files taking up space, you can delete them if you don’t need them anymore or you really need to make some space in your drive. Be careful here, make sure you’re not deleting anything important. If you’re unsure about a file, it’s best to leave it alone.

To delete a file, use the rm (remove) command.

For example, if you want to delete the movie from your Downloads folder, type:

rm /home/user/Downloads/movie.mkv

Tips for Deleting Safely:

  • Always double-check the file path before hitting enter.
  • Avoid deleting files from system folders like /var/ unless you know what you’re doing.

Step 4: Use “ncdu” for a Friendlier View

If you’re more of a visual person, there’s a tool called ncdu that makes finding large files even easier. It gives you a simple text-based interface showing you the biggest folders and files.

To install it, type:

sudo apt install ncdu

Once it’s installed, you can run it with:

sudo ncdu /

This will scan your system and show you a list of folders, sorted by size. You can navigate through the folders using the arrow keys and delete files directly from this interface by pressing d.

Example:

You’ll see something like this:

--- /home/user/Downloads ---
  2.3 GiB [##########]  movie.mkv
  1.5 GiB [#######   ]  another-movie.mkv
  512 MiB [###       ]  software.iso

From here, you can quickly spot what’s using up the most space and decide what to delete.

Step 5: Empty the Trash

One thing people often forget is that when you delete files, they don’t disappear right away, they go to the trash. So, after you’ve deleted some files, make sure to empty the trash to free up space for real.

To do this, you can either:

  • Open the Trash folder and click Empty Trash.
  • Or, in the terminal, type:
rm -rf ~/.local/share/Trash/*

This will permanently delete everything in the trash.

Step 6: Check Your Free Space

Once you’ve deleted the files, it’s a good idea to check how much space you’ve freed up. To do this, use the df command:

df -h

This will show you how much space is being used and how much is free, in a nice, easy-to-read format.

Example:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   30G   20G  60% /

In this example, you can see there’s now 20GB of free space on your system.

FAQs

What if I delete the wrong file?

Don’t panic, If you haven’t emptied the trash yet, you can usually recover the file from there. Just go to your Trash folder and restore it. If you’ve already emptied the trash, though, recovering it gets a lot harder, so be careful!

How can I avoid filling up my space again?

The best way is to regularly clean up files you don’t need. You can also use a tool like BleachBit to help clear out temporary files and junk. It’s free and easy to use.

What’s the difference between “rm” and “rmdir”?

Good question! The rm command is used to delete files, while rmdir is for removing empty directories. If you try to use rmdir on a folder that has files in it, it won’t work. You’ll need to use rm -r to delete the folder and its contents.

Conclusion

That’s it.. Now you know how to find and delete large files in Ubuntu. It might seem a bit technical at first, but with a little practice, it becomes second nature. Give it a go and see how much space you can free up. You’ll be surprised at how much smoother your system runs afterward.

Leave a Comment