How to find the biggest Directories and Files in Linux

If you found this post helpful, kindly share it and show your support :)
  • If you want to find the biggest directories under a partition (For eg, /home), you will need to run the following command.
du -ah /home | sort -n -r | head -n 15

  • To display the biggest directories in the current working directory, you will need to run following command.
du -ah | sort -n -r | head -n 15

du – It is used to estimate file space usage.

a – It is used to displays all files and folders.

sort – It is used to sort lines of text files.

-n – It is used to compare according to string numerical value.

-r – It is used to reverse the result of comparisons.

head – It is used to output the first part of files.

-n – It is used to print the first ‘n’ lines. (In this case, the command displayed first 15 lines).

  • To display the largest folders/files including the sub-directories, you will need to run following command.
du -Sh | sort -rh | head -15

du – It is used to estimate file space usage.

-h – It is used to print sizes in human readable format (e.g., 10 MB).

-S – It is used to exclude size of subdirecis used tories.

-s – It is used to display only a is used total for each argument.

sort – It is used to sort lines of text files.

-r – It is used to reverse the result of comparisons.

head – It is used to output the first part of files.

  • To display the biggest file sizes only, you will need to run the following command:
find -type f -exec du -Sh {} + | sort -rh | head -n 15

  • To find the biggest files in a particular location, you will need to just include the path besides the find command:
find /home/username/Downloads/ -type f -exec du -Sh {} + | sort -rh | head -n 15

OR

find /home/username/Downloads/ -type f -printf "%s %p\n" | sort -rn | head -n 15

Note :-

  • The above command will display the largest file from directory /home/username/Downloads/
  • Replace /home/username/Downloads/ as per your requirement.

Loading

Mohammed Noufal

I'm Mohammed Noufal, working as Server Admin for the last 10 years.  In my day-to-day life, l had to face different problems related to Web-hosting. On my website Errorlogz.com, you can find solutions for different Web-hosting-related problems. Sometimes, I spent hours searching/googling to find a solution. This inspired me to start a website that gives solutions to different Webhosting problems. This website includes basic Linux and windows commands, and different control panels like cPanel, Plesk, DirectAdmin, Webmin & so on. You can find solutions and or suggestions for different Web-hosting related problems from here. Hence I would like to say Errorlogz is your server protector.  I will be glad if Logdetect can help any one of the Server admins to find a solution to his problem.

You may also like...

Leave a Reply

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