We all have multiple files stored on our personal computers. At times, we might want to find the files that are occupying most of the space on our system so that we might move them somewhere else for freeing up the space on our system. Therefore, we have designed this article to teach you the method of finding the “n” largest files in Linux Mint 20.3 where “n” represents the number of the files to be found.
How to find “n” Largest Files in Linux Mint 20.3?
For explaining the method of listing the “n” largest files (where “n” represents the number of the files to be displayed) on the Linux Mint 20.3 terminal, we have formulated the following two examples for you.
Example # 1: Finding 8 Largest Files in a Particular Folder of Linux Mint 20.3:
In this example, we want to find out the 8 largest files or directories present within the Home directory of our system. It means that the value of “n” in this case is “8”. The command with which we are going to do this is stated below:
$ sudo du –a /home/ | sort –n –r | head –n 8
This command is basically a concatenation of multiple commands that we are going to talk about one by one. First, we have used the “du” command that stands for “disk usage” with the “-a” flag. This command will calculate the size of each file of the specified directory and extract their respective paths. Then, we have provided the path of the directory whose largest files we wanted to list down i.e. “home” in this case. After that, we have used the “sort” command with the “-n” and “-r” flags for sorting the output of the “du” command in descending order i.e. the file with the largest size will appear at the top and so on. Finally, we have used the “head” command with the “-n” flag for specifying the number of files to be found i.e. “8” in this case.
This command will have to compare the sizes of all the files present in the Home directory of our system for finding out the 8 largest files. Because of this, it will take a few minutes to complete its execution after which its output will appear on the terminal as shown in the following image:
Example # 2: Finding 2 Largest Files in a Particular Folder of Linux Mint 20.3:
In this example, we want to find the 2 largest files from our Home directory. For doing that, we will be using the exact same command that we have used in our first example. However, we will simply change the value of “n” from “8” to “2” as shown in the command below:
$ sudo du –a /home/ | sort –n –r | head –n 2
We have already explained this command in detail in our first example. Therefore, now we will just show you its output as displayed in the following image:
In this article, we explained to you the method of finding the “n” largest files in Linux Mint 20.3 by making use of two different examples. In the very same manner, you can replace the value of “n” with any desired integer according to the number of files that you want to find. Moreover, you can also specify the path according to your needs i.e. you can mention the path of any desired directory whose largest files or sub-directories you want to find out by using the method that has been prescribed in this article.