Find Largest Files on Linux


The search for large files is especially relevant when the disk runs out of space and you have to look for files to delete. The best way to find the largest files in a Linux server is to use the command line. You can easily get a list of the largest files using a combination of several simple commands.

Find Large Files on Linux or Unix server:


Find Large Files on Linux or Unix server

Find 10 files Linux server


Sometimes you can search for large files/directories, especially large log files that can quickly fill your server, with the following command you can find the top 10 largest files on the server:

du -a /var | sort -n -r | head -n 10



Find files for searching on whole filesystem


There are situations when you need to search for files throughout the file system. In this case, use the sudo command. With this command you will do all further actions as the root user. Please note that using this command all files will be found, including the USB drive if it is connected.

   First you need to open a terminal

   Next we will look for files file which is larger than 100MB

find / -type f -size +100M



Sometimes you need to find large files, and it is especially important to find large log files that can quickly fill up your server. With the following command you can find the 10 largest files on the server, which will be filtered in descending order.

find / -type f -exec du -sh {} 2>/dev/null + | sort -rh | head -n 10



find / -type f Find the largest files on the entire system
du -sh Display file size in human-readable format
sort -rh Reverse the result based on human-readable numbers
head -10 Display the first largest file

Find large files only in files:


Find large files only in files

Using this command you can skip directory searches and search only for large files using the find command

find /path/to/search/ -type f -printf '%s %p\n'| sort -nr | head -10



Find large directories and its subdirectories:


find /path/to/dir/ -printf '%s %p\n'| sort -nr | head -10


find . -printf '%s %p\n'| sort -nr | head -10



Find Large Unused Files


Find Large Unused Files

This is a very useful instruction, using which you can find the 10 largest files, the size of which is at least 10 MB, and which have not been used for more than 30 days.

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



How to Find the Largest Files with a specific extension in Linux


If you are looking for large files with a specific extension, you can find the top 10 largest files by their extension using the following command, we will use the “deb” extension in this case.

find / -type f -iname "*.deb" -exec du -sh {} + | sort -rh | head -10



Conclusion


In this article, we used various commands and tried to show the most used ones, which can help you quickly find all large files in a Linux system.