How To Find Largest Files & Folders on Linux

Free space on your disk by detecting large files and folders in Linux that take up a lot of space.

Today this tutorial will analyze in Ubuntu which folders or files occupy space in the system and in this way execute management tasks on them.

Find Largest Folders in Linux

The first command that we will execute is to find the largest files in a specific path, in this example we want to visualize the files that occupy more space in the /home folder, for this, we execute the following.

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

To find the largest folders in all paths, we will execute the following command:

du -a | sort -n -r | head -n 7

Parameters explained:

du: It is responsible for determining the size of space occupied by the file.

-a: Unfold all folders and files .

sort: It is responsible for ordering the lines .

-n: Compare the numerical values of the chains.

-r: It is responsible for inverting the result of the comparisons.

head: Display the file header.

-n #: It refers to the number of lines to be displayed.

If we want to know in detail the size of those directories, whether, in KB, MB or GB, we will execute the following command:

du -hs * | sort -rh | head -4 (First (4) largest directories)

With this command we display the main directories, but if we want to show both directories and subdirectories to check the space consumed, we will execute the following, indicating at the end the number of lines to be displayed:

du -Sh | sort -rh | head -11

Find Largest Files in Linux

At times we want to deploy exclusively the largest files stored in the system and take actions on them for this we will execute the following command:

find -type f -exec du -Sh {} + | sort -rh | head -n 6

This will display the 6 bulkiest files in the system:

To find the bulkiest files in a defined path, for example, Downloads, we will use the following line:

find /home/solvetic/Descargas -type f -exec du -Sh {} + | sort -rh | head -n 3

Or we can also use the following:

find /home/solvetic/Descargas -type f -printf "%s %p\n" | sort -rn | head -n 3

As we see we have several options to take a specific control over the files, folders or directories that occupy more space in Linux and from this information make the appropriate control decisions.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *