How to Find Large Files in Linux

Learn how to easily mantain and manage your filesystems.

Largest File

Identifying large files on your PC can help you quickly reclaim some much needed space. For desktop Linux users, hunting down large unnecessary files might be optional. But when it comes to server space, it costs money, and you have to pay for that excess space every month. Here’s how you can locate big files in Linux to quickly get rid of them.

Use the ls Command

Generally, the ls command is used to list all of the directories and files in the Linux terminal. However, it can do much more – for instance, classify directory contents and display file sizes.

  1. To see more information about files and directories including their permissions, you can use the -l flag.
ls -l
Largest File 1
  1. To print their size along with all of the information, use the -s flag along with the previous -l flag.
ls -ls
Largest File 3
  1. By default, the ls command will only list the directories. To see the files inside the directories recursively, use the -R flag.
ls -lsR
Largest File 4
  1. To sort files, you can use two methods. One takes advantage of the -S flag inside the ls command, while the other employs the power of the sort command. To sort the files according to their file size in descending order, run the following command:
ls -lsRS
Largest File 5
  1. To reverse the order, you can use the -r flag.
ls -lsRSr
Largest File 6
  1. Alternatively, after the ls command returns, you can pipe the result into the sort command. This will sort the list as per their numerical file sizes in ascending order. You can also reverse the order by using -r flag in conjunction with the sort command.
ls -ls | sort -nr
Largest File 7
  1. So far, we have analyzed and found the largest files inside our current working directory. To identify the largest file in your whole filesystem, you can add the location after the ls command.
sudo ls / -S
Largest File 8

Use the find Command

The find command can be used to search any files inside a Linux filesystem. In this case, we can employ it to list files according to their file sizes. We can also filter the results by minimum file size.

  1. To find the largest files inside your current working directory, type the following:
find . -type f
Largest File 12
  1. It’s possible to also add a filter with the minimum size of 100MB.
find . -type f -size +100M
Largest File 10
  1. To specify a certain directory, add the relative path after the find command.
find ./test -type f -size +100M
  1. Doing so will find all the files inside the “test” directory which has a size greater than 100MB.
  2. Sometimes you need to search the entire filesystem to find the largest file. For that, just add a / after the find command.
sudo find / -xdev -type f -size +100M

Note: the -xdev flag instructs not to descend directories on other filesystems. In simple words, it won’t scan other mounted filesystems in your Linux system.

  1. To remove this behavior and to scan all the mounted drives along with your primary filesystem, just remove the -xdev command as follows:
sudo find / -type f -size +100M

Now you should be able to view the list of the largest files in your entire device along with your mounted drives.

Use the du Command

The du command is primarily designed to estimate file sizes in Linux. Here’s how to find large files with it.

  1. You can use the -a flag to list the files along with directory sizes recursively.
du -a
Largest File 13
  1. The file sizes listed here appear as very long number strings, so they are very hard to estimate. To make it readable, use the -h flag in conjunction with other flags.
du -ah
Largest File 15 1
  1. To make the file size uniform, use the blocksize operator -B along with a unit of your choice. If you want to convert the sizes in MB, use unit M as a block size.
du -aBM
Largest File 17
  1. To find the largest files among them, use the sort command to sort the files in descending order.
du -aBM | sort -nr
  1. To list only the first five results, pipe the sorted list into the head command by using -n 5.
du -aBM | sort -nr | head -n 5
Largest File 18
  1. So far we’ve been displaying file sizes only in our current working directory. To list the largest files of a specific directory, append the directory name after the du command. The following command will list the five largest files in your home directory.
du /home -aBM | sort -nr | head -n 5
  1. To find the largest 10 files in your entire filesystem, just add the / after the du command.
du / -aBM | sort -nr | head -n 10

Find Large Unused Files

Getting the list of unused files is very useful, as you can readily delete them to save space on your hard disk. Do this with the help of the -mtime flag and the find command discussed earlier. The following instructions will list out the top 10 files, which have not been modified for more than 30 days and have a file size of at least 100MB.

find / -xdev -mtime +30 -type f -size +100M

GUI Apps to Find the Largest Files in Linux

If you are running Linux on your desktop, make use of these GUI apps to find the largest files in your system.

Disk Usage Analyzer

One of the best GUI apps to analyze file sizes in Linux is Disk Usage Analyzer. It comes preinstalled in your Gnome desktop environment.

  1. If this application is not installed on your machine, you can easily install the disk usage analyzer application like so:
sudo apt update
sudo apt install baobab

For Fedora or other red-hat-based distributions, install Disk Usage Analyzer by using the following command:

sudo dnf install baobab
  1. Open the app and select the filesystem you want to scan. Disk Usage Analyzer will list the attached filesystem in your machine.
  2. You’ll have to wait a few seconds until the scan completes.
  3. Once the process is done, you’ll be able to see the list of files and folders sorted according to their sizes (larger ones at the top, smaller towards the bottom).
Largest File 19
  1. You can navigate through the folders using double clicks.

Some additional GUI apps that you can use to find large files on your Linux system include:

Remove the Largest Files

After finding the largest files, you need to remove them and can easily do so with the help of therm command in Linux.

  1. Copy the absolute or relative file of the file you want to delete, then append the file path after the rm command.
rm "your file path goes here"
  1. To remove any non-empty directory, use the -rf after the rm command. -r represents recursively deleting the files inside the directory, and -f implies force to delete that directory. For example, if you want to delete your “Downloads” folder along with all the files inside it, run the following command.
rm -rf ~/Downloads

Frequently Asked Questions

Why I am getting a "permission denied" error?

If you want to run a command beyond your home directory, you should have root permission. Otherwise, you will get the permission denied error. Try using sudo before the command to elevate your permission as a root user. You can successfully run any command on your system files. Try to be careful when using sudo with commands.

How do I find files larger than 1GB?

To find files larger than 1GB, use the find command with its -size flag. The command will look like this: sudo find / -xdev -type f -size +1G.

How can I view the size of a particular folder?

To see the size of a folder, use any of the tools mentioned in this article. You can also use your File Explorer to see the size of a folder. Just right-click on the folder and select the properties option. There you can easily find the listed folder size.

Image source: Unsplash All screenshots Hrishikesh Pathak

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox