How To Find Large Files In Linux?

Linux is a file-based operating system that contains a lot of files of different sizes. During daily usage, a lot of files are created or downloaded by systems or users. This consumes a lot of disk space which results in storage errors and warnings. We can search and find big or large files using different commands and tools where some of them may not be needed anymore. In this tutorial, we examine different commands, methods, and tools to fine large files in Linux.

Find Large Files with du Command

The du command is used to list files and folders for their disk usage or storage usage. We can use du with the sort and head commands in order to list large files. We will use the sort command to sort files according to their sizes. The file sizes are printed as bytes. The head command is used to list only the top 20 files.

$ du -a . | sort -n -r | head -n 20
Find Large Files with du Command

We can also specify a different path than the current working directory. In the following example, we list large files located inside the “/home/ismail”.

$ du -a /home/ismail | sort -n -r | head -n 20

Create Alias To Find Large Files

As the previous example contains a lot of commands chained together it is very hard to type or remember this command. We can create a bash alias for this command group in order to remember and call them easily. Put the following line to the users ~/.bashrc file to create llf alias.

alias llf = "du -a /home/ismail | sort -n -r | head -n 20"

Find Large Files with find Command

The find command is the official command to search files in Linux. The find command has a lot of features and one of them is the ability to search files according to their size. We can list file sizes and redirect to the sort command to sort files according to their sizes.

$ find /home/ismail -type f -printf '%s %p\n' | sort -nr | head -10

Find Large Files with Specified Extension

As the find command provides a lot of features we can search large files according to their extension. The -name option is used to specify the file name or extension. In the following example, we search large files with the *.iso extension.

$ find /home/ismail -name "*.iso" -type f -printf '%s %p\n' | sort -nr | head -10

Find Large Files Bigger Than Specified Size

The find command can list large files that are bigger than the specified size. The -size option is used to specify the size. In the following example, we list large files whose sizes are bigger than 200MB.

$ find /home/ismail -size +200M -type f -printf '%s %p\n' | sort -nr | head -10

Leave a Comment