How to Find Large Files on Linux?
Linux’s Family of operating systems is a group of open-source operating systems that are based on the Linux kernel that was developed and released in 1991. Linux is one of the most popular operating systems among software developers and professional users. In this article, we will discuss some methods that can be used to locate and isolate Large Files in a particular directory. Make sure to follow the steps carefully and accurately in order to avoid conflict.
How to Find Large Files on Linux?
There are a lot of methods which can be used to find large files on a Linux but we have only compiled some of the most convenient ones below.
Method 1: Through du Command
There are a couple of commands in Linux that can help the user to find and sort certain files in a directory depending upon their size and location. In this step, we will be combining a few commands to sort the files in a particular directory according to their size. For that:
- Press the “Ctrl” + “Alt” + “T” buttons simultaneously to launch the terminal.
- Type in the following command and press “Enter” to login as a root user.
sudo-i
- Type in the following command and press “Enter” to find the largest file on the directory.
$ sudo du -a /dir/ | sort -n -r | head -n 20
Note: du is used to calculate the file size, the “sort” will list the output of the du command according to the sizes and the “head” limits the response to only the 20 largest files.
- You can also use the following command to achieve the same task.
$ sudo du -a / 2>/dev/null | sort -n -r | head -n 20
- Linux will now list the top 20 largest files in the indicated directory.
Method 2: Using Find Command
If you want to directly find the largest file and not the directory which hosts it, you can combine the “Find” command to list the required output. For that:
- Press the “Ctrl” + “Alt” + “T” buttons simultaneously to launch the terminal.
- Type in the following command and press “Enter” to login as a root user.
sudo-i
- Type in the following command and press “Enter” to find the largest file on the computer.
$ sudo find / -type f -printf "%s\t%p\n" | sort -n | tail -1
- After that, type in 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.