Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to Linux, so sorry for my simple question. I'm on Ubuntu.

I have this directory:

$ ls -al
total 16
drwxr-xr-x 2 alberto alberto 4096 2011-04-03 16:02 .
drwxr-xr-x 4 alberto alberto 4096 2011-04-03 16:01 ..
-rw-r--r-- 1 alberto alberto    7 2011-04-03 16:02 .hidden
-rw-r--r-- 1 alberto alberto    4 2011-04-03 15:51 testfile

When I run du, I'm expecting this:

$ du
4   testfile
4   .hidden

But I'm getting this:

$ du
12  .
$ du *
4   testfile
$ du .*
12  .
20  ../snippet
12  ../test
52  ..
4   .hidden

Why is this happening?

share|improve this question
As an extra thing to consider, commands never see shell globs like * unless quoted. Shell expands it and passes the results to the command. So du * turns into du testfile and du .* turns into du . .. .hidden. This is why * always works and always works in the same way. – XTL Jun 8 '12 at 7:25
up vote 7 down vote accepted

du summarizes the disk usage directory by directory. In your example, since the current directory has no subdirectory, the output is a single line.

If you pass the name of a file on the command line, its size is reported. If you pass the names of multiple files, this is equivalent¹ to running du multiple times; hence du .* is equivalent to du .; du ..; du .hidden.

Run du -a to see the space occupied by each file.

 $ du -a
 4   .hidden
 4   testfile
 12  .

¹ Almost: on some systems, if a regular file has multiple hard links, then it's only counted the first time it's reached in a particular du invocation.

share|improve this answer
The second sentence of your second paragraph is not true. If files foo and bar are hardlinks to the same file, then du foo bar, du bar foo and du foo; du bar will each output something different. – Steven Monday Apr 3 '11 at 15:43
@Steven: Yes, you're right, I wanted to keep things simple. Not all implementations do that, though. With GNU, du foo bar counts the file only once, but OpenBSD counts it twice. POSIX favors the GNU behavior, but I don't find it very clear on the case of multiple command line arguments. – Gilles Apr 3 '11 at 15:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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