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

Introduction

Finding out which directories and files are taking up the most disk space in Linux can be a daunting task. Fortunately, there are a few simple commands that can help you quickly identify the biggest culprits. In this guide, we will show you how to use the du and ncdu commands to find the most used disk space directories and files in Linux. We will also discuss some other useful commands that can help you analyze disk usage.

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

1. Use the du command: The du command is used to estimate file space usage. It can be used to find the size of a directory and its subdirectories. To find the most used disk space directories and files, run the following command:

du -h –max-depth=1 /

This will show the size of each directory in the root directory.

2. Use the ncdu command: The ncdu command is a disk usage analyzer with an ncurses interface. It provides a fast way to see what directories and files are using the most disk space. To find the most used disk space directories and files, run the following command:

ncdu /

This will show a list of directories and files sorted by size.

3. Use the find command: The find command is used to search for files in a directory hierarchy. It can be used to find the largest files and directories on a system. To find the most used disk space directories and files, run the following command:

find / -type f -printf ‘%s %p\n’ | sort -nr | head -n 10

This will show the 10 largest files and directories in the root directory.
[ad_1]

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 Jassweb.

[ad_2]

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

If you are a Linux user, you may have noticed that your disk space is slowly being taken up by files and directories. It can be difficult to determine which files and directories are taking up the most disk space. Fortunately, there are a few simple commands that can help you find the most used disk space directories and files in Linux.

Using the du Command

The du command is a useful tool for finding out which directories and files are taking up the most disk space. To use the du command, open a terminal window and type the following command:

du -h --max-depth=1

This command will show you a list of all the directories and files in the current directory, along with their size in human-readable format. The –max-depth=1 option limits the output to the current directory only, so you won’t see any subdirectories or files in the output.

Using the ncdu Command

The ncdu command is a more powerful version of the du command. It provides a graphical interface that makes it easier to find the most used disk space directories and files. To use the ncdu command, open a terminal window and type the following command:

ncdu

This will open the ncdu interface, which will show you a list of all the directories and files in the current directory, along with their size. You can then use the arrow keys to navigate through the list and find the most used disk space directories and files.

Using the find Command

The find command is another useful tool for finding the most used disk space directories and files. To use the find command, open a terminal window and type the following command:

find . -type f -printf '%s %p\n' | sort -nr | head -n 10

This command will show you a list of the 10 largest files in the current directory, along with their size. You can then use the ls command to view the contents of the directories and files that are taking up the most disk space.

Conclusion

Finding the most used disk space directories and files in Linux can be a difficult task. However, with the help of the du, ncdu, and find commands, you can easily find the most used disk space directories and files in Linux.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00