+5 votes
152 views
in Linux/Unix by (242k points)
reopened
Larger Linux Files | Find

1 Answer

+3 votes
by (1.6m points)
 
Best answer

How to find large files in Linux

We use our computer to generate, share and receive information of all kinds, so we usually store different content in different formats to be able to access it whenever we need it. However, the problem with this is that little by little the storage of our PC is filling up..

 

 

In our operating systems we normally store all types of files, from text to videos, we leave them in folders or directories depending on the type of operating system using. In the case of Linux these are directories and little by little saving files will fill up the space on the hard disk and may even affect its performance.

 

That is why as administrators or users we must look for the functional way to detect the files that occupy the most space in a directory to determine the degree of importance of these and thus see if it is possible to eliminate them or simply move them to another location..

 

getFastAnswer will explain the process to find the file size in Linux.

 

 

To stay up to date, remember to subscribe to our YouTube channel!   SUBSCRIBE

 

 

How to find large files in Linux


For this process we will use the du command, this is a command that allows us to obtain information about the use of the hard disk. This focuses on the directories, we have different parameters to use in order to obtain details, these are:

 

End each line of output with NULL
 -0, –null 

Writes the count of all files, not just directories
 -a, –all 

Print apparent sizes, rather than actual disk usage
 –Apparent-size 

Scale sizes to SIZE before printing to console
 -B, –block-size = SIZE 

Generates the grand total of the directory size
 -c, –total 

prints the total for the directory only if it is N or fewer levels that are less than the command line argument
 d, –max-depth = N 

Print the result in human-readable format
 -h, –human-readable 

Applies to directories, in this case it does not include the size of the subdirectories -s, –summarize: shows only the total of each directory
 -S, -separate-dirs 

Displays the time of the last modification of any file or directory.
 –Time 

 

Now let's see how to use du on Linux to find large files based on the given criteria..

 

Step 1

To start, let's run du with the ah parameters to:
  • -a which allows us to access all directories and subdirectories
  • -h with which it is possible to obtain the information in readable language
 du -ah / home 
image

 

Step 2

It is possible to increase the depth level of the directory to be analyzed, for this we execute the following:
 du -ha –max-depth = 1 / home 
image

 

Step 3

With du we can establish an order in the way the results are displayed, additionally list X amount of line, for example, we can list 20 lines with readable data:
 sudo du -h / | sort -rh | head -20 
image

 

We see the 20 lines with specific details of its size.

 

Step 4

Another of the available options is to list the global total, for this we will execute:
 du -chs * 
image

 

Step 5

This command is in charge of displaying the size of all the directories, for one in particular we execute:
 du -chs / home 
image

 

These are the options that du offers us to manage and know the size of the directories in Linux.

 


...