How to Find Highest Disk Consuming Files and Directories in Linux?

As a website owner, you may face the issue of disk quota exceeded that means the disk drive get cluttered with large number of files and directories which may be unnecessary. So, it is important to find those files or directories in order to check if they are consuming unwanted space.

In this article, we will illustrate the procedure to find highest disk consuming files and directories in Linux.

Highest Disk Consuming Files and Directories in Linux
Highest Disk Consuming Files and Directories in Linux

We will discuss some of the Linux commands that will help you to find large files and directories in Linux.

  1. By using du command
  2. By using find command
  3. By using ls command

#1. By Using du command

Following are the commands that can help you to get large files and directories in Linux.

  • The below given command will help you to find top 5 large files or directories in the particular location.
du -a /home | sort -n -r | head -n 5

Refer to the below mentioned image.  To get inside a directory you can use cd command with path of directory. You can change the number 5 with other as required.

  • The command will display the highest disk consuming files and directories in human readable format.
    du -hs * | sort -rh | head -5

Refer to the above image.

  • The command will display the list of highest disk consuming directories with sub-directories.
    du -Sh | sort -rh | head -5

From the above image it can be observed that which sub-directory inside a directory is consuming more space.

#2. By Using find command

Another command that you can use to find highest disk consuming files and directories is find command.

  • The below given command will display only the large sized files.
    find -type f -exec du -Sh {} + | sort -rh | head -n 5

You can change number 5 as required.

  • The below command will display the files and directories which is larger that 50MB.
    find -type f -size +50M

To get more details about these files, execute the following command.

find -type f -size +50M -exec ls -alh {} \; | sort -nk 5

Refer to the below mentioned image.                   

  • You can also find the highest disk consuming files and directories in a particular location by adding the path of the directory as:
    find /path/of the/directory/ -type f -exec du -Sh {} + | sort -rh | head -n 4

From the above image, it can be observed that by adding path of the directory after find command with the proceeding arguments will display the large files and directories of that particular location.

#3. By Using ls command

ls command with multiple arguments will help you to find highest consuming file sand directories in Linux system.

  • The below mentioned command will list all the large files and directories ordered by file or directory consuming more disk space on the top.
    ls -alhS
total 2.3M
drwxr-xr-x  2 test test 4.0K Jul  1 16:11 folder
drwxr-xr-x  5 test test 4.0K Jul 20 13:52 wp
-rw-r--r--  1 test test  373 Jan  4  2022 all.zip
-rw-r--r--  1 test test  311 Jul 20 14:43 new.html
-rw-r--r--  1 test test   75 Jan  8  2022 date.php
-rw-r--r--  1 test test   40 Dec 31  2021 test.php
-rw-r--r--  1 test test   14 Dec 27  2021 index.htmlabc
-rw-r--r--  1 test test    8 Apr 20 13:30 file.php
  • The next command given below will display the size of files or directories in the current directory in human readable format. You can mention the path as well if required without using cd command to get inside the directory.
ls -lhtr
total 14M
-rw-r--r--   1 root root  21K Feb 11  2010 shc-3.8.7.tgz 
-rw-r--r--   1 root root   10 Jan  6  2021 installer.lock 
drwxr-xr-x   4 root root 4.0K Jan  7  2021 cpanel3-skel 
-rw-r--r--   1 root root  46K Sep 11 11:14 lshw-info.html
-rw-r--r--   1 root root  60K Sep 11 11:14 jetbackup_export_1631339053.tar 
drwxr-xr-x   3 root root 4.0K Sep 11 11:14 zipper 
-rw-r--r--   1 root root   64 Sep 11 11:14 abusers.txt 
-rw-r--r--   1 root root  791 Sep 11  2021 rescue.sh 
-rw-r--r--   1 root root  60K Sep 11  2021 jetbackup_export_1631339067.tar 
-rw-r--r--   1 root root  17K Sep 11  2021 Screenshot_5.png

That’s It !

Thus, the above explained commands will help you to find highest disk consuming files and directories in Linux. Do share it with your colleagues if you find it working. Connect with us on social media pages.

Facebook Page: https://facebook.com/redserverhost                                                                                       Twitter Page: https://twitter.com/redserverhost.com

Scroll to Top