I was looking through my system with du -sch ./* to find the big useless files I may have stockpiled with no reason, when I found this:

$ du -sch ./* du: cannot read directory ‘./drbunsen/.gvfs’: Permission denied du: cannot read directory ‘./drbunsen/.cache/dconf’: Permission denied 18G ./drbunsen 18G total $ cd drbunsen/ $ du -sch ./* 601M ./Desktop 20K ./Documents 598M ./Downloads 4.0K ./flash 4.0K ./Music 8.0M ./Pictures 4.0K ./Public 4.0K ./Templates 4.0K ./Ubuntu One 8.0K ./Videos 11G ./VirtualBox VMs 6.9M ./workspace 12G total 

How do I make hidden files visible? du -sch ./.* gives the same result as du -sch ./*.

2

5 Answers

Use

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

in your home folder.

Alternatively, the command I use most frequently is

ncdu 

Easy to install if needed:

sudo apt-get install ncdu 
5

I have same question in coreutils mailing list, because it was hard to me to remember this weird command by @don.joey. And Bob Proulx proposed better, more natural command: du -ahd1 | sort -h

If you want to list all of the files in the current directory then either use '.' or don't give it any file arguments at all. Also you may want to use the -d, --max-depth=N option.

Try this:

du -hd1

2

When you run that same command inside the directory, it is not including the hidden files which start with . in the count. If you have Steam for example installed, it default to installing games under ~/.local/share/Steam/ and it itself is installed there as well.

Under bash you apparently need to run du -sch .[!.]* * as it does not properly expand the .* glob. Under zsh or other shells, du -sch * .* should work, as .* should be expanded to include the list of all hidden files in the current directory.

3

This also works to show hidden files and dirs:

du -sch $(ls -A .) | sort -h 
1

I don't think the du utility has a command line switch to process hidden files by default.

One way of achieving this is to use the find utility to find the hidden files that you are interested in and then run the du utility on each entry:

find ./ -maxdepth 1 -name '.*' -exec du -hs {} \; 

This gives you additional flexibility as you may only be interested in directories:

find ./ -maxdepth 1 -type d -name '.*' -exec du -hs {} \; 

Or you may want to see all hidden files and directories deep to the current working directory:

find ./ -name '.*' -exec du -hs {} \; 

It's not much harder to sort the output, so you can easily identify large hidden files that could help you save disk space:

{ find ./ -maxdepth 1 -iname '.*' -exec du -hs \{\} \; ;} | sort -h