10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories

The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk usage of files and directories on a machine. The du command has many parameter options that can be used to get the results in many formats. The du command also displays the files and directory sizes in a recursively manner.

Check Disk Usage In Linux

Check Disk Usage of Files and Folders In Linux

This article explains 10 useful “du” commands with their examples, that might helps you to find out the sizes of files and directories in Linux. The information provided in this article are taken from the man pages of du command.

Read Also:

  1. 12 “df” Command to Check Linux System Disk Space
  2. Agedu – A Useful Tool for Tracking Down Wasted Disk Space in Linux

1. To find out the disk usage summary of a /home/tecmint directory tree and each of its sub directories. Enter the command as:

[[email protected]]# du  /home/tecmint

40      /home/tecmint/downloads
4       /home/tecmint/.mozilla/plugins
4       /home/tecmint/.mozilla/extensions
12      /home/tecmint/.mozilla
12      /home/tecmint/.ssh
689112  /home/tecmint/Ubuntu-12.10
689360  /home/tecmint

The output of the above command displays the number of disk blocks in the /home/tecmint directory along with its sub-directories.

2. Using “-h” option with “du” command provides results in “Human Readable Format“. Means you can see sizes in Bytes, Kilobytes, Megabytes, Gigabytes etc.

[[email protected]]# du -h /home/tecmint

40K     /home/tecmint/downloads
4.0K    /home/tecmint/.mozilla/plugins
4.0K    /home/tecmint/.mozilla/extensions
12K     /home/tecmint/.mozilla
12K     /home/tecmint/.ssh
673M    /home/tecmint/Ubuntu-12.10
674M    /home/tecmint

3. To get the summary of a grand total disk usage size of an directory use the option “-s” as follows.

[[email protected]]# du -sh /home/tecmint

674M    /home/tecmint

4. Using “-a” flag with “du” command displays the disk usage of all the files and directories.

[[email protected]]# du -a /home/tecmint

4       /home/tecmint/.bash_logout
12      /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
24      /home/tecmint/downloads/Phpfiles-org.tar.bz2
40      /home/tecmint/downloads
12      /home/tecmint/uploadprogress-1.0.3.1.tgz
4       /home/tecmint/.mozilla/plugins
4       /home/tecmint/.mozilla/extensions
12      /home/tecmint/.mozilla
4       /home/tecmint/.bashrc
689108  /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
689112  /home/tecmint/Ubuntu-12.10
689360  /home/tecmint

5. Using “-a” flag along with “-h” displays disk usage of all files and folders in human readeable format. The below output is more easy to understand as it shows the files in Kilobytes, Megabytes etc.

[[email protected]]# du -ah /home/tecmint

4.0K    /home/tecmint/.bash_logout
12K     /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
24K     /home/tecmint/downloads/Phpfiles-org.tar.bz2
40K     /home/tecmint/downloads
12K     /home/tecmint/uploadprogress-1.0.3.1.tgz
4.0K    /home/tecmint/.mozilla/plugins
4.0K    /home/tecmint/.mozilla/extensions
12K     /home/tecmint/.mozilla
4.0K    /home/tecmint/.bashrc
673M    /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M    /home/tecmint/Ubuntu-12.10
674M    /home/tecmint

6. Find out the disk usage of a directory tree with its subtress in Kilobyte blcoks. Use the “-k” (displays size in 1024 bytes units).

[[email protected]]# du -k /home/tecmint
40      /home/tecmint/downloads
4       /home/tecmint/.mozilla/plugins
4       /home/tecmint/.mozilla/extensions
12      /home/tecmint/.mozilla
12      /home/tecmint/.ssh
689112  /home/tecmint/Ubuntu-12.10
689360  /home/tecmint

7. To get the summary of disk usage of directory tree along with its subtrees in Megabytes (MB) only. Use the option “-mh” as follows. The “-m” flag counts the blocks in MB units and “-h” stands for human readable format.

[[email protected]]# du -mh /home/tecmint

40K     /home/tecmint/downloads
4.0K    /home/tecmint/.mozilla/plugins
4.0K    /home/tecmint/.mozilla/extensions
12K     /home/tecmint/.mozilla
12K     /home/tecmint/.ssh
673M    /home/tecmint/Ubuntu-12.10
674M    /home/tecmint

8. The “-c” flag provides a grand total usage disk space at the last line. If your directory taken 674MB space, then the last last two line of the output would be.

[[email protected]]# du -ch /home/tecmint

40K     /home/tecmint/downloads
4.0K    /home/tecmint/.mozilla/plugins
4.0K    /home/tecmint/.mozilla/extensions
12K     /home/tecmint/.mozilla
12K     /home/tecmint/.ssh
673M    /home/tecmint/Ubuntu-12.10
674M    /home/tecmint
674M    total

9. The below command calculates and displays the disk usage of all files and directories, but excludes the files that matches given pattern. The below command excludes the “.txt” files while calculating the total size of diretory. So, this way you can exclude any file formats by using flag “-–exclude“. See the output there is no txt files entry.

[[email protected]]# du -ah --exclude="*.txt" /home/tecmint

4.0K    /home/tecmint/.bash_logout
12K     /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
24K     /home/tecmint/downloads/Phpfiles-org.tar.bz2
40K     /home/tecmint/downloads
12K     /home/tecmint/uploadprogress-1.0.3.1.tgz
4.0K    /home/tecmint/.bash_history
4.0K    /home/tecmint/.bash_profile
4.0K    /home/tecmint/.mozilla/plugins
4.0K    /home/tecmint/.mozilla/extensions
12K     /home/tecmint/.mozilla
4.0K    /home/tecmint/.bashrc
24K     /home/tecmint/Phpfiles-org.tar.bz2
4.0K    /home/tecmint/geoipupdate.sh
4.0K    /home/tecmint/.zshrc
120K    /home/tecmint/goaccess-0.4.2.tar.gz.1
673M    /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M    /home/tecmint/Ubuntu-12.10
674M    /home/tecmint

10. Display the disk usage based on modification of time, use the flag “–time” as shown below.

[[email protected]]# du -ha --time /home/tecmint

4.0K    2012-10-12 22:32        /home/tecmint/.bash_logout
12K     2013-01-19 18:48        /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
24K     2013-01-19 18:48        /home/tecmint/downloads/Phpfiles-org.tar.bz2
40K     2013-01-19 18:48        /home/tecmint/downloads
12K     2013-01-19 18:32        /home/tecmint/uploadprogress-1.0.3.1.tgz
4.0K    2012-10-13 00:11        /home/tecmint/.bash_history
4.0K    2012-10-12 22:32        /home/tecmint/.bash_profile
0       2013-01-19 18:32        /home/tecmint/xyz.txt
0       2013-01-19 18:32        /home/tecmint/abc.txt
4.0K    2012-10-12 22:32        /home/tecmint/.mozilla/plugins
4.0K    2012-10-12 22:32        /home/tecmint/.mozilla/extensions
12K     2012-10-12 22:32        /home/tecmint/.mozilla
4.0K    2012-10-12 22:32        /home/tecmint/.bashrc
24K     2013-01-19 18:32        /home/tecmint/Phpfiles-org.tar.bz2
4.0K    2013-01-19 18:32        /home/tecmint/geoipupdate.sh
4.0K    2012-10-12 22:32        /home/tecmint/.zshrc
120K    2013-01-19 18:32        /home/tecmint/goaccess-0.4.2.tar.gz.1
673M    2013-01-19 18:51        /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M    2013-01-19 18:51        /home/tecmint/Ubuntu-12.10
674M    2013-01-19 18:52        /home/tecmint

Read Also :

  1. 10 fdisk Commands to Manage Linux Disk Partitions
  2. 12 Useful “df” Commands to Check Disk Space in Linux
Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

30 Responses

  1. K. de Jong says:

    A kilobyte is 1000 bytes, always has (referring to the -k switch part). A kilo is always a unit of 1000 (e.g. a kilometer is also 1000 meters). A kibibyte is 1024 bytes. I know that Americans aren’t used to the metric system, but please, get it right when you do use it. I see these mistakes happen in blogs like these all the time…

  2. jilson says:

    How can i find the 1st five largest in the file /etc.

  3. Ayush says:

    If I want to calculate the size of files with particular extensions in a directory. How can I calculate it?

  4. Stranger says:

    Does any one know or experienced the output of “du -csh” mismatched with grand total ?

    For ex: du -csh *
    10M File_A
    14M Dir_A
    22M total

    but expectation is 24 MB as total.

  5. Cedric says:

    I would like to mention also this combination, in order to find the biggest sub-folders in current location:

    du -h –max-depth=1

    thanks

    • no one in particular says:

      Yes – I ended up going to an ancient site looking for that switch – it should be like number 2 on the list.

      fyi: On some systems – freebsd is particular, depth is just -d [depth] – so “du -d 1 -h” is the secret sauce for the question ‘wtf happened to my space?’

  6. rlinux57 says:

    Is is possible to collect historical data analysis of disk space usage per user ?

    • Ravi Saive says:

      @rlinux,

      No you can’t use du (disk usage) command to get the disk space usage per user, yes but you can do use some command-line tricks with the help of find and awk command to find out the disk space usage for all users on the system including root user, here is the command.

      # find . -printf "%u  %s\n" | awk '{user[$1]+=$2}; END{ for( i in user) print i " " user[i]}'
      
      • rlinux57 says:

        But i need want to get the historical disk space usage, not current usage.

        • soft says:

          You could start a cron to run this command at different times to log the historical data
          find / -printf “%u %s\n” | awk ‘{user[$1]+=$2}; END{ for( i in user) print i ” ” user[i]}’

          • soft says:

            find / -printf “%u %s\n” | awk ‘{user[$1]+=$2}; END{ for( i in user) print i ” ” user[i]}’ > /yourlogdir/log_`date +_%m_%d_%Y_%H%M%S`

  7. rosh says:

    Another nice option is to sort by size: du -h * | sort -h

  8. Ashish Karpe says:

    how to find du of / ie when I ran du -sh / it gives du: cannot access `./proc/14498/task/14518/fdinfo/35147′: No such file or directory
    du: cannot access `./proc/14498/task/14518/fdinfo/35156′: No such file or directory

  9. Yasminhth says:

    Thanks for tips. Well explain ans example

  10. abhi says:

    very nice work. It helped me.

Leave a Reply to Stranger Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.