How to Find Large Files on Linux?
In this article, we will explore several methods that you can use to locate and isolate large files within a specific directory in Linux. Be sure to follow the steps carefully to avoid any issues.
While there are numerous ways to find large files on Linux, we have selected some of the most convenient methods for you.
Method 1: Using the du Command
In Linux, there are several commands available to help you locate and sort files in a directory based on their size and location. In this method, we will combine a few commands to sort files in a specific directory according to their size.
- Press the “Ctrl” + “Alt” + “T” keys at the same time to open the terminal.
- Type the following command and press “Enter” to log in as a root user.
sudo -i
- Enter the following command and press “Enter” to find the largest files in the directory.
$ sudo du -a /dir/ | sort -n -r | head -n 20
Note: The du command is used to calculate file sizes, sort arranges the output based on size, and head limits the output to the 20 largest files.
- You can also use this command to perform the same task:
$ sudo du -a / 2>/dev/null | sort -n -r | head -n 20
- Linux will now display the top 20 largest files in the specified directory.
Method 2: Using the Find Command
If you want to directly locate the largest file itself, rather than just the directory hosting it, you can use the “find” command to generate the required output.
- Press the “Ctrl” + “Alt” + “T” keys simultaneously to open the terminal.
- Type the following command and press “Enter” to log in as a root user.
sudo -i
- Enter this command and press “Enter” to locate the largest file on your computer.
$ sudo find / -type f -printf "%s\t%p\n" | sort -n | tail -1
- Next, type the following command and press “Enter“.
$ find $HOME -type f -printf '%s %p\n' | sort -nr | head -10
- These commands will list the largest files available.