bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: du reports different results for "."


From: Bob Proulx
Subject: Re: du reports different results for "."
Date: Wed, 20 Feb 2008 16:30:55 -0700
User-agent: Mutt/1.5.13 (2006-08-11)

Richard Ems wrote:
> If I do a "du -s * ." and right afterwards "du -s ." I get different
> values for the actual directory ".".

Note that 'du -s * .' will stat every file twice because effectively
it was listed twice in the command line argument list.

> This is on Linux, openSUSE 10.3, coreutils-6.9-43, xfs filesystem.
>
> Example:
> 
> # du -s * . | grep "\.$" ; du -s .
> 23227004        .
> 25251176        .
> 
> Is this correct "du" behavior ?

I can't reproduce your problem.  Here is what I tried using the
current stable du release 6.10:

  mkdir testdir
  cd testdir
  dd if=/dev/zero of=a count=19
  dd if=/dev/zero of=b count=23
  dd if=/dev/zero of=c count=29

  $ ls -ldog .
  drwxrwxr-x 2 4096 2008-02-20 16:04 ./

  $ ls -ldog --block-size=1024 .
  drwxrwxr-x 2 4 2008-02-20 16:04 ./

  $ du -s *
  12      a
  12      b
  16      c

  $ echo $((12+12+16+4))
  44

  $ du -s * .
  12      a
  12      b
  16      c
  44      .

  $ du -s .
  44      .

As you can see here the sizes always add up to 44 for me.

As others have suggested hidden files, files matching options,
activity in the directory tree at that time the behavior doesn't seem
unreasonable.  You don't know until you know.

I would strace both runs of du and then look at the data from the
lstat calls and see if the data is changing for any of the runs.

  $ strace -v -e trace=file du -s *

Directory ordering may cause du to traverse in a different order than
sorted order such as in the above.  But the st_blocks should be the
same between runs.  If not then the difference is because those files
changed size.  This following might help to pull out the st_blocks
values and sum them.

  strace -v -e trace=file du -s * 2>&1 \
  | awk '/st_blocks=/{sub(/.*st_blocks=/,"");sub(/,.*/,"");t+=$0}END{print t}'

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]