How to Find Most Used Disk Space Directories and Files in Linux

As a Linux administrator, you must periodically check which files and folders are consuming more disk space. It is very necessary to find unnecessary junk and free it up from your hard disk.

This brief tutorial describes how to find the largest files and folders in the Linux file system using the du (disk usage) and find commands. If you want to learn more about these two commands, then head over to the following articles.

How to Find Biggest Files and Directories in Linux

Run the following command to find out the top biggest directories under /home partition.

# du -a /home | sort -n -r | head -n 5
Find Largest Directories in Linux
Find Largest Directories in Linux

The above command displays the biggest 5 directories of my /home partition.

Find Largest Directories in Linux

If you want to display the biggest directories in the current working directory, run:

# du -a | sort -n -r | head -n 5
Find Biggest Directories Only
Find the Biggest Directories Only

Let us break down the command and see what says each parameter.

  • du command: Estimate file space usage.
  • a : Displays all files and folders.
  • sort command : Sort lines of text files.
  • -n : Compare according to string numerical value.
  • -r : Reverse the result of comparisons.
  • head : Output the first part of the files.
  • -n : Print the first ‘n’ lines. (In our case, We displayed the first 5 lines).

Some of you would like to display the above result in a human-readable format. i.e. you might want to display the largest files in KB, MB, or GB.

# du -hs * | sort -rh | head -5
Find Top Directories Sizes in Linux
Find Top Directories Sizes in Linux

The above command will show the top directories, which are eating up more disk space. If you feel that some directories are not important, you can simply delete a few sub-directories or delete the entire folder to free up some space.

To display the largest folders/files including the sub-directories, run:

# du -Sh | sort -rh | head -5
Find Largest Folder and Sub directories
Find the Largest Folder and Subdirectories

Find out the meaning of each option using in above command:

  • du command: Estimate file space usage.
  • -h : Print sizes in human-readable format (e.g., 10MB).
  • -S : Do not include the size of subdirectories.
  • -s : Display only a total for each argument.
  • sort command : sort lines of text files.
  • -r : Reverse the result of comparisons.
  • -h : Compare human readable numbers (e.g., 2K, 1G).
  • head : Output the first part of the files.

Find Out Top File Sizes Only

If you want to display the biggest file sizes only, then run the following command:

# find -type f -exec du -Sh {} + | sort -rh | head -n 5
Find Top File Sizes in Linux
Find Top File Sizes in Linux

To find the largest files in a particular location, just include the path beside the find command:

# find /home/tecmint/Downloads/ -type f -exec du -Sh {} + | sort -rh | head -n 5
OR
# find /home/tecmint/Downloads/ -type f -printf "%s %p\n" | sort -rn | head -n 5
Find Top File Size in Specific Location
Find the Top File Size in a Specific Location

The above command will display the largest file from /home/tecmint/Downloads directory.

That’s all for now. Finding the biggest files and folders is no big deal. Even a novice administrator can easily find them. If you find this tutorial useful, please share it on your social networks and support TecMint.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.