How to Find the Top 10 Largest Files in Linux

When you are running out of disk space in system, you may prefer to check with df command or du command or ncdu command.

But all these will only show you current directory files and doesn’t show the system wide files.

You have to spend huge amount of time to get the largest files on the system using the above commands and you have to go to every directory to achieve this.

It’s making you to face trouble, and this is not the right way to do it.

What is the best way to get the top 10 largest files in Linux?

I spent a lot of time on Google, but I could not find the right one. This is because most articles list the top 10 files from the current directory, but not from the entire system.

So, I want to make this article useful for people who want to get the top 10 big files from the whole system.

In this tutorial, we are going to show you how to find the top 10 largest files on a Linux system using different methods.

Method-1:

There is no specific command in Linux to find this, so we use several commands together to find it.

# find / -type f -print0 | xargs -0 du -h | sort -rh | head -n 10

1.4G	/swapfile
1.1G	/home/magi/ubuntu-17.04-desktop-amd64.iso
564M	/home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqTFU0XzkzUlJUZzA
378M	/home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqeldzUmhPeC03Zm8
377M	/home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqRGd4V0VrOXM4YVU
100M	/usr/lib/x86_64-linux-gnu/libOxideQtCore.so.0
93M	/usr/lib/firefox/libxul.so
84M	/var/lib/snapd/snaps/core_3604.snap
84M	/var/lib/snapd/snaps/core_3440.snap
84M	/var/lib/snapd/snaps/core_3247.snap

Details:
find : It’s a command, Search for files in a directory hierarchy.
/ : Check in the whole system (starting from / directory)
-type : To select type of file.
f : Regular file
-print0 : Print the full file name on the standard output, followed by a null character
| : Control operator that send the output of one program to another program for further processing.
xargs : It’s a command to build and execute command lines from standard input.
-0 : Input items are terminated by a null character instead of by whitespace
du -h : It’s a command to calculate disk usage with human readable format
sort : It’s a command to sort lines of text files
-r : Reverse the result of comparisons
-h : Print the output with human readable format
head : It’s a command to output the first part of files
n -10 : Print the first 10 files.

Method-2:

This is an another way to find the top 10 largest files in Linux system.

# find / -type f -exec du -Sh {} + | sort -rh | head -n 10

1.4G	/swapfile
1.1G	/home/magi/ubuntu-17.04-desktop-amd64.iso
564M	/home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqTFU0XzkzUlJUZzA
378M	/home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqeldzUmhPeC03Zm8
377M	/home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqRGd4V0VrOXM4YVU
100M	/usr/lib/x86_64-linux-gnu/libOxideQtCore.so.0
93M	/usr/lib/firefox/libxul.so
84M	/var/lib/snapd/snaps/core_3604.snap
84M	/var/lib/snapd/snaps/core_3440.snap
84M	/var/lib/snapd/snaps/core_3247.snap

Details:
find : It’s a command, Search for files in a directory hierarchy.
/ : Check the whole system (starting from / directory)
-type : To select type of file.
f : Regular file
-exec : This variant of the -exec action runs the specified command on the selected files
du : It’s a command to estimate file space usage.
-S : Do not include size of subdirectories
-h : Print sizes in human readable format
{} : Summarize disk usage of each FILE, recursively for directories.
| : Control operator that send the output of one program to another program for further processing.
sort : It’s a command to sort lines of text files
-r : Reverse the result of comparisons
-h : Compare human readable numbers
head : It’s a command to output the first part of files
n -10 : Print the first 10 files.

Method-3:

It’s an another method to find or search top 10 biggest files in Linux system.

# find / -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

84M	/var/lib/snapd/snaps/core_3247.snap
84M	/var/lib/snapd/snaps/core_3440.snap
84M	/var/lib/snapd/snaps/core_3604.snap
93M	/usr/lib/firefox/libxul.so
100M	/usr/lib/x86_64-linux-gnu/libOxideQtCore.so.0
377M	/home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqRGd4V0VrOXM4YVU
378M	/home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqeldzUmhPeC03Zm8
564M	/home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqTFU0XzkzUlJUZzA
1.1G	/home/magi/ubuntu-17.04-desktop-amd64.iso
1.4G	/swapfile

Details:
find : It’s a command, Search for files in a directory hierarchy.
/ : Check in the whole system (starting from / directory)
-type : File is of type

f : Regular file
-print0 : Print the full file name on the standard output, followed by a null character
| : Control operator that send the output of one program to another program for further processing.

xargs : It’s a command to build and execute command lines from standard input.
-0 : Input items are terminated by a null character instead of by whitespace
du : It’s a command to estimate file space usage.

sort : It’s a command to sort lines of text files
-n : Compare according to string numerical value
tail -10 : It’s a command to output the last part of files (last 10 files)

cut : It’s a command to remove sections from each line of files
-f2 : Select only these fields value.
-I{} : Replace occurrences of replace-str in the initial-arguments with names read from standard input.

-s : Display only a total for each argument
-h : Print sizes in human readable format
{} : Summarize disk usage of each FILE, recursively for directories.

References:

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...