I want to see sizes of all directory including hidden directory.
One command I came across was this :
du -hs .[!.]*
but it is giving me error :
du: cannot access ‘.[!.]*’: No such file or directory
I can't make out what I am doing wrong.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The error you’re getting means that there is no hidden file or directory in the current directory.
.[!.]* expands to match any file or directory whose name starts with “.” followed by anything but “.”; if it doesn’t match anything, it is left as is by default. So in your case,
du is run with
.[!.]* as its argument, instead of real file or directory names, and it produces the error message you’re seeing.
You can enable
nullglob to change the shell’s behaviour here:
shopt -s nullglob
Then the shell will remove patterns which match nothing, and
du will report the usage of the current directory if nothing matches (that’s its default behaviour in the absence of arguments).
To achieve what you’re after, in Bash, you should do this instead:
du -sh .[!.]*/ */
This will expand to all directories in the current directory, including hidden ones. If
nullglob isn’t enabled it will still produce error messages, but you’ll see the sizes of any directory that matches.