find large files in Ubuntu
How To

Find Large Files on Ubuntu

Sagar Sharma
Sagar Sharma

Table of Contents

Removing unnecessary large files is one of the best ways to free up some space in Ubuntu but the question is how you are supposed to find those large files.

To find large files, I will be using the find command and will share the following practical ways to find large files in Ubuntu:

  • Find files larger than the X size
  • Find and sort large files
  • Find useless large files

So let's start with the first one.

📋
In this tutorial, I will be showing how you find the large files from the root directory and that'd require superuser privileges.

How to find files larger than the X size

Finding files larger than the X size would help you identify those giants taking the major part of your storage drive.

I assume anything that is bigger than 500MB so here's the command to find files that are larger than 500MB:

sudo find / -xdev -type f -size +500M 
Find file larger than specific size using the find command in Ubuntu

Now, let's breakdown the command:

  • sudo: To elevate privileges and find large files from the root directory.
  • find: The command that'd get you the list of the large files.
  • /: Indicates the search will begin from the root directory.
  • -xdev: It will restrict the search for the current filesystem only and won't look into other mounted filesystems.
  • -type f : Used to list files only.
  • -size +500M: To list files that are larger than 500MB.

Similarly, if you want to find large files from a specific directory, you can give a path to that directory.

For example, here, I wanted to list large files of the current directory, then I used the following command:

find . -xdev -type f -size +500M 
List large files from specific directory

Wondering why I used . instead of adding the path of the home directory.

Perks of learning how to use the find command! When you use the ., it will begin to search in the current working directory.

How to find large files and sort them

This is an expanded version of the above command where I will be using the find command with exec and pipe it to the sort command.

And here's the command that lists files larger than 500MB and sorts the list in descending order:

sudo find / -xdev -type f -size +200M -exec du -h {} + | sort -rh
List large files and sort them using the find command in Ubuntu

Here,

  • -exec du -h {} +: The exec command will execute the du command with the -h flag to find filesize. {} + is placeholder indicates the list should be bound by the result of the find command.
  • |: Symbol of pipe which is used to pipe two commands in Linux.
  • sort -rh: Here, I have used the sort command where the -r flag was used to list files in descending order and the -h flag gives output in human-readable form.

How to find large useless files in Ubuntu

The word useless may vary from user to user but to generalize things, I assume a file that has not been modified in the last 100 days can be labeled as useless.

First, let's take a look at the command and then, will break down every part:

sudo find / -xdev -mtime +100 -type f -size +500M  

And this is the output I got:

sagar@Learnubuntu:~$ sudo find / -xdev -mtime +100 -type f -size +500M
/usr/lib/libexample.so
/home/user/documents/bigfile.iso
/var/log/archive.log

Here, I have used the mtime command to list files older than 100 days.

More on finding files and disk space

You may also want to know how to check the directory size in Ubuntu.

How to Check Directory Size in Ubuntu Command Line
Not getting the directory size with the ls command? Here’s how to check the folder size in the Ubuntu command line.

And why stop at finding files when you can go on and check the disk space.

Check Disk Space in the Ubuntu Command Line
Wondering what’s the disk size? How much free space you have left? Learn about checking disk space in the Ubuntu command line.

If you don't know, find is considered as one of the most powerful commands in Linux but it has a bad reputation of being complex.

But worry not! To help you out, we made a detailed guide on how you can use the find command with super useful examples:

15 Super Useful Examples of Find Command in Linux
Learn the super powerful and super useful find command with these practical examples.

I hope you will find this guide helpful.



Sagar Sharma

Sagar Sharma

A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.