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 disk usage information 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 recursive manner.

This article explains useful ‘du‘ commands with examples, which can help you determine the sizes of files and directories in Linux. The information provided in this article is sourced from the ‘du‘ command’s man pages.

How to Find the Size of a Directory in Linux

1. To obtain a summary of disk usage for a directory tree ‘/home/tecmint‘ and its subdirectories, use the following command.

# du /home/tecmint

4       /home/tecmint/bin
4       /home/tecmint/.ffbinaries-cache
672     /home/tecmint/.openjfx/cache/17.0.3-ea
676     /home/tecmint/.openjfx/cache
680     /home/tecmint/.openjfx
36      /home/tecmint/.ssh
92      /home/tecmint/.config/xfce4/xfconf/xfce-perchannel-xml
96      /home/tecmint/.config/xfce4/xfconf
12      /home/tecmint/.config/xfce4/desktop
...
56758808	/home/tecmint

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

Find Disk Usage of Directory
Find Disk Usage of Directory

How to Find the Directory Size in Human Readable Format

2. By employing the '-h' option with the ‘du‘ command, you can obtain results in a ‘Human Readable Format‘, which enables you to view sizes in units such as Bytes, Kilobytes, Megabytes, Gigabytes, and so on.

# du -h /home/tecmint

4.0K    /home/tecmint/bin
4.0K    /home/tecmint/.ffbinaries-cache
672K    /home/tecmint/.openjfx/cache/17.0.3-ea
676K    /home/tecmint/.openjfx/cache
680K    /home/tecmint/.openjfx
36K     /home/tecmint/.ssh
92K     /home/tecmint/.config/xfce4/xfconf/xfce-perchannel-xml
96K     /home/tecmint/.config/xfce4/xfconf
12K     /home/tecmint/.config/xfce4/desktop
...
55G	/home/tecmint
Check Disk Usage of Directory
Check Disk Usage of Directory

How to Find Total Size of a Directory in Linux

3. To obtain a summary of the total disk usage size for a directory, use the '-s' option as follows.

# du -sh /home/tecmint

55G	/home/tecmint
Find Directory Size in Linux
Find Directory Size in Linux

4. Utilizing the '-a' flag with the ‘du‘ command displays the disk usage of all files and directories.

# du -a /home/tecmint

4       /home/tecmint/fix-deb-src-error-ubuntu
4       /home/tecmint/tecmint.py
0       /home/tecmint/bin/FoxitReader
4       /home/tecmint/bin
4       /home/tecmint/.ffbinaries-cache
52      /home/tecmint/Eclipse-with-PyDev.jpg
300     /home/tecmint/Screenshot from 2023-07-27 14-02-45.png
16      /home/tecmint/.openjfx/cache/17.0.3-ea/libglass.so
28      /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font_pango.so
20      /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font.so
64      /home/tecmint/.openjfx/cache/17.0.3-ea/libprism_es2.so
512     /home/tecmint/.openjfx/cache/17.0.3-ea/libglassgtk3.so
...
56759528	/home/tecmint
Check File and Directory Size
Check File and Directory Size

5. Employing the '-a' flag along with '-h' displays the disk usage of all files and folders in a human-readable format. The resulting output is easier to comprehend, as it presents file sizes in units such as Kilobytes, Megabytes, and so on.

# du -ah /home/tecmint

4.0K    /home/tecmint/fix-deb-src-error-ubuntu
4.0K    /home/tecmint/tecmint.py
28K     /home/tecmint/download.php?file=%2Foomph%2Fepp%2F2023-06%2FR%2Feclipse-inst-jre-linux64.tar.gz.1
0       /home/tecmint/bin/FoxitReader
4.0K    /home/tecmint/bin
4.0K    /home/tecmint/.ffbinaries-cache
52K     /home/tecmint/Eclipse-with-PyDev.jpg
300K    /home/tecmint/Screenshot from 2023-07-27 14-02-45.png
16K     /home/tecmint/.openjfx/cache/17.0.3-ea/libglass.so
28K     /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font_pango.so
20K     /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font.so
64K     /home/tecmint/.openjfx/cache/17.0.3-ea/libprism_es2.so
512K    /home/tecmint/.openjfx/cache/17.0.3-ea/libglassgtk3.so
...
55G	/home/tecmint
List File and Directory Size
List File and Directory Size

6. To determine the disk usage of a directory tree and its subdirectories in Kilobyte blocks, utilize the '-k' option (displays sizes in 1024 bytes units).

# du -k /home/tecmint

4       /home/tecmint/bin
4       /home/tecmint/.ffbinaries-cache
672     /home/tecmint/.openjfx/cache/17.0.3-ea
676     /home/tecmint/.openjfx/cache
680     /home/tecmint/.openjfx
8       /home/tecmint/.uk.co.screamingfrog.seospider.ui.b/webview
12      /home/tecmint/.uk.co.screamingfrog.seospider.ui.b
36      /home/tecmint/.ssh
92      /home/tecmint/.config/xfce4/xfconf/xfce-perchannel-xml
96      /home/tecmint/.config/xfce4/xfconf
12      /home/tecmint/.config/xfce4/desktop
4       /home/tecmint/.config/xfce4/xfwm4
8       /home/tecmint/.config/xfce4/panel/launcher-18
8       /home/tecmint/.config/xfce4/panel/launcher-17
8       /home/tecmint/.config/xfce4/panel/launcher-14
8       /home/tecmint/.config/xfce4/panel/launcher-3
8       /home/tecmint/.config/xfce4/panel/launcher-16
8       /home/tecmint/.config/xfce4/panel/launcher-5
...
56769128	/home/tecmint

7. To obtain a summary of the disk usage for a directory tree, including its subdirectories, in Megabytes (MB) only, use the '-mh' option as follows. The '-m' flag counts the blocks in MB units and '-h' stands for human-readable format.

# du -mh /home/tecmint

4.0K    /home/tecmint/bin
4.0K    /home/tecmint/.ffbinaries-cache
672K    /home/tecmint/.openjfx/cache/17.0.3-ea
676K    /home/tecmint/.openjfx/cache
680K    /home/tecmint/.openjfx
8.0K    /home/tecmint/.uk.co.screamingfrog.seospider.ui.b/webview
12K     /home/tecmint/.uk.co.screamingfrog.seospider.ui.b
36K     /home/tecmint/.ssh
92K     /home/tecmint/.config/xfce4/xfconf/xfce-perchannel-xml
96K     /home/tecmint/.config/xfce4/xfconf
12K     /home/tecmint/.config/xfce4/desktop
4.0K    /home/tecmint/.config/xfce4/xfwm4
8.0K    /home/tecmint/.config/xfce4/panel/launcher-18
8.0K    /home/tecmint/.config/xfce4/panel/launcher-17
8.0K    /home/tecmint/.config/xfce4/panel/launcher-14
8.0K    /home/tecmint/.config/xfce4/panel/launcher-3
...
55G	/home/tecmint

8. The '-c' flag provides a grand total of the disk space usage at the last line. If your directory takes up 55GB of space, then the last two lines of the output would appear as follows.

# du -ch /home/tecmint

4.0K    /home/tecmint/bin
4.0K    /home/tecmint/.ffbinaries-cache
672K    /home/tecmint/.openjfx/cache/17.0.3-ea
676K    /home/tecmint/.openjfx/cache
680K    /home/tecmint/.openjfx
8.0K    /home/tecmint/.uk.co.screamingfrog.seospider.ui.b/webview
12K     /home/tecmint/.uk.co.screamingfrog.seospider.ui.b
36K     /home/tecmint/.ssh
92K     /home/tecmint/.config/xfce4/xfconf/xfce-perchannel-xml
96K     /home/tecmint/.config/xfce4/xfconf
12K     /home/tecmint/.config/xfce4/desktop
4.0K    /home/tecmint/.config/xfce4/xfwm4
8.0K    /home/tecmint/.config/xfce4/panel/launcher-18
8.0K    /home/tecmint/.config/xfce4/panel/launcher-17
8.0K    /home/tecmint/.config/xfce4/panel/launcher-14
8.0K    /home/tecmint/.config/xfce4/panel/launcher-3
8.0K    /home/tecmint/.config/xfce4/panel/launcher-16
...
55G	/home/tecmint
55G	total

How to Exclude Files with du Command

9. The following command calculates and displays the disk usage of all files and directories, excluding files that match the given pattern.

In the provided example, the command excludes '.txt' files when calculating the total size of a directory. This approach allows you to exclude specific file formats using the '--exclude' flag.

Upon reviewing the output, you’ll notice the absence of entries for '.txt' files.

# du -ah --exclude="*.txt" /home/tecmint

4.0K    /home/tecmint/fix-deb-src-error-ubuntu
4.0K    /home/tecmint/tecmint.py
0       /home/tecmint/bin/FoxitReader
4.0K    /home/tecmint/bin
4.0K    /home/tecmint/.ffbinaries-cache
52K     /home/tecmint/Eclipse-with-PyDev.jpg
300K    /home/tecmint/Screenshot from 2023-07-27 14-02-45.png
16K     /home/tecmint/.openjfx/cache/17.0.3-ea/libglass.so
28K     /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font_pango.so
20K     /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font.so
64K     /home/tecmint/.openjfx/cache/17.0.3-ea/libprism_es2.so
512K    /home/tecmint/.openjfx/cache/17.0.3-ea/libglassgtk3.so
28K     /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font_freetype.so
672K    /home/tecmint/.openjfx/cache/17.0.3-ea
...
55G	/home/tecmint

How to Find Directory Usage By Modification Time

10. To display disk usage based on the modification time, use the '--time' flag as shown below.

# du -ha --time /home/tecmint

4.0K    2023-07-06 13:15        /home/tecmint/fix-deb-src-error-ubuntu
4.0K    2023-06-14 12:50        /home/tecmint/tecmint.py
0       2021-12-07 12:26        /home/tecmint/bin/FoxitReader
4.0K    2021-12-07 12:26        /home/tecmint/bin
4.0K    2022-10-10 11:02        /home/tecmint/.ffbinaries-cache
52K     2023-05-12 12:09        /home/tecmint/Eclipse-with-PyDev.jpg
300K    2023-07-27 14:02        /home/tecmint/Screenshot from 2023-07-27 14-02-45.png
16K     2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea/libglass.so
28K     2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font_pango.so
20K     2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font.so
64K     2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea/libprism_es2.so
512K    2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea/libglassgtk3.so
28K     2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font_freetype.so
672K    2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea
676K    2022-10-01 12:41        /home/tecmint/.openjfx/cache
...
55G	2023-08-14 10:22	/home/tecmint

The du command is versatile and can be tailored to your needs using various options and flags. Use man du in the terminal for more detailed information about its options and usage.

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.

32 Comments

Leave a Reply
  1. 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…

    Reply
  2. 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.

    Reply
    • There can be two reasons (that I can think of):

      One is Rounding:

      The sizes are quite quickly rounded up (a few k over the mark is enough).

      10M File_A – might be 9.2M
      14M Dir_A – might be 13.2M
      23M total – because that adds up to 22.4, which again is rounded up.

      But I think that can’t explain it fully.

      It might be because you simplified your example and there are more of these files/directories of a few k which all get rounded up to 1M.

      – The functioning of *
      Another way is that there are files/directories starting with . in your main directory.
      These are not shown in the list when you use *, but they are calculated in the total of the main directory.

      Reply
  3. 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

    Reply
    • 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?’

      Reply
    • @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]}'
      
      Reply
        • 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]}’

          Reply
          • 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`

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

    Reply
  5. Hi Ravi,

    Can you please help me with a command which can provide the Disk I/O Limit.

    Please Note that, i am asking for the Disk I/O limit not the current io rate given by iostat.

    Regards,
    Manoj Rana

    Reply
  6. Is there a way to only include certain types of files.

    For example, something like:

    du -ah –include=”*.php” /home/tecmint

    PS: That’s a very helpful post – thanks for sharing!

    Reply
    • You can run any command that gives you results in linux/unix by piping it through a grep command. So all you need to accomplish your task is something simple like du -ah | grep php. It would not accomplish your task perfectly since you would get files with php in the name as well but you would dig up all the .php files.

      Reply

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.