I want to estimate the amount of disk space used by a directory using the following command.

du -sh dir_name

which does not calculate the hidden directories. In the man page of du there is no info regarding it. How to calculate the amount of disk space used by the directories including the hidden files.

13 Answers 13


Actually it does, here is the proof:

mkdir .test
echo "hi" > .test/appo
du -a
4       ./.test/appo
8       ./.test
12      .

The -a option is used to explicitly show which files were counted.

Are you using du *?

  • 16
    +1 for ... you maybe using "du *" ?
    – sehe
    Oct 3, 2011 at 11:34
  • 3
    I am not using "du *". I forgot to mention in the question that i need the total summary summary. so if i use both -a and -s as in du -as i get an error message saying "du: cannot both summarize and show all entries". This is one issue. The other thing is that i even with du -a i get to see only the first level files. i.e unable to see files inside hidden directories. Oct 3, 2011 at 11:50
  • 1
    I just added -a to show all files being counted, just don't add that flag, it only affect the display, not the totals. I showed you a counter-example that instead hidden directories are counted.
    – stivlo
    Oct 3, 2011 at 11:56
  • 4
    now i found the problem. The problem was the hidden directory was a symbolic link, So i had to use "du -Lsh dir_name". Thanks. Oct 3, 2011 at 12:47
  • 2
    ah, I see, glad that you found it, cheers.
    – stivlo
    Oct 3, 2011 at 13:03

This command shows you the summarized size of hidden directories using a regular expression:

du -hs .[^.]*
  • it would be awesome if you could explain a bit the magic behind it. it would help to form an answer which includes both hidden and non hidden files and directories.
    – kumetix
    Nov 5, 2019 at 14:21
  • 3
    Glob expression: Take the 1st dot but don't take the 2nd dot => don't go to your parent. Find your (hiding / playing peek-a-boo) children and report their size back to me.
    – Ashfaq
    May 30, 2020 at 4:51
  • /home# du -hs .[^.]* du: cannot access '.[^.]*': No such file or directory Dec 16, 2020 at 9:32
  • 10
    It seems that du -hs .[^.]* * will include both dot files/directories and non-hidden directories together. I don't know if there are cases where this is not correct.
    – steveb
    Jan 27, 2021 at 23:32
  • 2
    If you are crazy enough to have filesnames like "..tralala", you have to include them too du -hs ..[^.]* .[^.]* *
    – Hrobky
    Jul 9, 2021 at 15:25

The correct command is : du -hs $(ls -A)

$ du -hs $(ls -A)
0   test
0   .test

du -hs .* *, as mentioned in another answer, is not correct if you want to list all files and subdirectories (including hidden ones).

Example :

$ touch test
$ touch .test
$ echo *
$ echo .* *
. .. .test test
$ du -hs .* *
4,0K    .
1,8G    ..

Why does du behave like this? Because you use -s that summarize the result and that all files and subdirectories are children of . so du -hs does not list them!

  • 5
    For file names with spaces, this command will produce an error
    – Kariem
    Jan 22, 2021 at 13:04
  • This gives du for both hidden (.*) and non-hidden. Additionally, it ignores the parent. Accurate command. Oct 5, 2021 at 7:58
  • 1
    The only good answer here. May 12 at 9:08

FYI, for estimating the size occupied by various directories, its much better to use ncdu

You can navigate in the ncurses GUI between various directories and it will show the size of each directories. If I am using du, I would have to execute du command for each directory I want to check for which can be cumbersome. You can sort the directories according to the size occupied too in the ncurses GUI.

  • 1
    Please edit your answer to indicate why you believe ncdu to be "much better". The linked page doesn't really say anything about it other than that it's an ncurses-based version of du. Aside from a fancier display method, there's no obvious indication of any functional difference. Oct 4, 2011 at 10:15
  • 1
    I think the ability to dynamically adjust your query is a huge benefit. I can run ncdu on ~, learn which directories are using the most space and then dive directly into those. It also gives you the d binding to delete directories, so you can clean up directly from the interface.
    – user88974
    Mar 17, 2017 at 10:06
du -ahd1 | sort -hr | head -10

following is the description of -d option in du --help:

-d, --max-depth=N print the total for a directory (or file, with --all) only if it is N or fewer levels below the command line argument; --max-depth=0 is the same as --summarize

  • Although this may help to solve the problem, it doesn't explain why and/or how it addresses the issue. Providing this additional context would significantly improve its long-term educational value. Please edit your answer to add explanation, including what limitations and assumptions apply. Thanks.
    – fixer1234
    Nov 26, 2018 at 12:31

It does and it does not. Example:

In the home directory: (only one user exist)

du -sh /home/*
2.6G    /home/user

in the user directory: (huge difference between the sums)

du -sh *
61M     bin
2.0M    dump-20130124104823.tar.gz
651M    public_html
472K    twitter-2.0.0.gem
11M     wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2

and the reason is:

du -sh /home/user/.rvm/
1.9G    /home/user/.rvm/

du will calculate hidden directories while descending into subdirectories, but in the current directory the * simply does not match to .directory_name pattern so the current directory hidden elementes will be omitted.

It took me some time to figure out, and as shadyabhi recommends it would have been obvious if i had used ncdu.


You can use the following command:

find -maxdepth 1 -exec du -sh "{}" \; | sort -h

This gives you:

  • Size of hidden files/directories
  • Size of non-hidden files/directories
  • Grand total size of the current directory

It also sorts the output to make it easy to see what is the largest. I also made this an alias in my ~/.bash_aliases file.

alias big='find -maxdepth 1 -exec du -sh "{}" \; | sort -h'
alias sbig='sudo find -maxdepth 1 -exec du -sh "{}" \; | sort -h'

Now I can just execute big to find the biggest directories in a directory and sbig when I need sudo permissions.


This command will help you to check the disk usage, go to your directory and execute the following:

du -sch .[!.]* * | sort -h

Here is a demo of how to calculate disk usage of a particular directory.

I have created a directory called Du_sh and created two files inside of it (one hidden [10 MB] and one normal [20 MB]).

nikhil@debian:~$ mkdir Du_sh
nikhil@debian:~$ cd Du_sh/
nikhil@debian:~/Du_sh$ dd if=/dev/zero of=.10MB bs=1024 count=10240
10240+0 records in
10240+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0299941 s, 350 MB/s
nikhil@debian:~/Du_sh$ dd if=/dev/zero of=20MB bs=2048 count=10240
10240+0 records in
10240+0 records out
20971520 bytes (21 MB, 20 MiB) copied, 0.0342258 s, 613 MB/s
nikhil@debian:~/Du_sh$ du -sch .[!.]* * 
10M .10MB
20M 20MB
30M total
nikhil@debian:~/Du_sh$ du -sch .[!.]* * | sort -h
10M .10MB
20M 20MB
30M total

Most things I tried (including other answers) didn't work in one way or another, so here is my (currently) final solution for using du:

ls -A | while read file; do du -sh "$file"& done | sort -h;
  • ls -A All files including hidden, without . and ..
  • while read file; do du -sh "$file"& done Run the du command on each entry from ls -A in parallel. Had no problem yet regarding too much parallelism, but you can either replace & by ; making it synchronous or add [ $( jobs | wc -l ) -ge $( nproc ) ] && wait before done
  • sort -h Sort by size

While I'm at it: I have a function named dus added to my profile to keep this function at hand:

dus () { ls -A | while read file; do du -sh "$file"& done | sort -h; }

The correct command is:

du -hs .* *

From man pages:

   -h, --human-readable
          print sizes in human readable format (e.g., 1K 234M 2G)

   -s, --summarize
          display only a total for each argument

You can read more about du command here.

  • 1
    Some additional information would make this an acceptable answer.
    – Ramhound
    Sep 23, 2014 at 12:07
  • For me du * .* -sh works instead.
    – tejasvi88
    Jan 29 at 9:05

du accepts paths. With this command you can check the disk usage of a different path:

du -sh /path/to/directory/{.[^.],}*

If you want the result sorted (bigger files/dirs first):

du -sh /path/to/directory/{.[^.],}* | sort -hr

You may use braces expansion with wildcarding and human readable sorting:

du -hd2 {.,[^.]}* | sort -h

d2 is a depth option


I found this comment by Stéphane Chazelas worth a separate answer for zsh users.

On zsh, use:

du -sch *(D) | sort -h

The solutions with .[^.]* * or .[!.]* * do not work on zsh if a folder contains only .* files or * files. It will throw a no matches found error. So you cannot use one command universally.

On bash, it would return the following error for one type but still continue with the other type.

No such file or directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.