Operating System - HP-UX
1819736 Members
2854 Online
109606 Solutions
New Discussion юеВ

Does the du command show hidden files?

 
SOLVED
Go to solution
Tony Williams
Regular Advisor

Does the du command show hidden files?

While looking for files that filled up a file system it appears that the du command does not report on "dot" files or directories. The directory had 500MB according to du -sk ., but du -sk * didn't show any files or directories that totaled more than 20MB. a ll | wc -l showed 141 entries, and a du -sk * | wc -l showed 112. The descrepancy were all dot files. The file (errorlog) that was filling up the file system was in a .vue directory. Is there a way to force du to look at hidden and regular files/directories?
7 REPLIES 7
Robert-Jan Goossens
Honored Contributor
Solution

Re: Does the du command show hidden files?

Hi,

# du -a
Reports every file in this directory.

Hope this helps,
Robert-Jan
harry d brown jr
Honored Contributor

Re: Does the du command show hidden files?

Try this:

find . -type f -exec du -skr {} \;

live free or die
harry
Live Free or Die
Ernesto Cappello
Trusted Contributor

Re: Does the du command show hidden files?

Hi ...

# du -ak

where
-a Print entries for each file encountered
in the directory hierarchies in
addition to the normal output.
-k Gives the block count in 1024-byte
blocks.

For further information "man du".
Regards, Ernesto.

Mel Burslan
Honored Contributor

Re: Does the du command show hidden files?

the asterisk in the command "du -sk *" did not resolve into the filenames starting with dot character. The filenames beginning with dot character needs to be explicitly addressed. It is not the deficiency of du command it is the regex expansion rule of the shell as far as I know.
________________________________
UNIX because I majored in cryptology...
Patrick Wallek
Honored Contributor

Re: Does the du command show hidden files?

The fault here is not with du, rather it is with the '*' wildcard character. The definition of the '*' wildcard is one or more alphanumeric characters. Anytime you use just a '*', be it with du, ls, tar, whatever, it will ALWAYS ONLY get files that start with an alphanumberic character.

In order to get du to pick up the '.*' files and directories you must modify you du command.

Something like this would work:

# du -ks * .[a-zA-Z]*

The .[a-zA-Z]* will get only dot-files that start with upper or lower case a-z. If you have dot-files that start with numbers you could do it like .[a-zA-Z0-9]* You don't want to do just .* as that will get the .. directory which will go down thru the parent directory which would not be good.



harry d brown jr
Honored Contributor

Re: Does the du command show hidden files?

If you use the

du -a -k

command, it will list files and directory's giving the appearance of double totals:

0 ./lost+found
0 ./.AgentSockets/A
4134 ./.AgentSockets/dah
4134 ./.AgentSockets
2 ./rpcbind.file

Whereas, the find command (find . -type f -exec du -sk {} \;) will give you just files:

4134 ./.AgentSockets/dah
2 ./rpcbind.file

live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: Does the du command show hidden files?


And you can try this:

find /tmp -type f -exec du -k {} \; | awk 'BEGIN {totsize=0;totcnt=0;} {totsize+
=$1;totcnt+=1;} END {print totcnt,"files consuming",totsize,"blocks";}'

live free or die
harry
Live Free or Die