Re: Finding the size of directory with multiply hardlinked files

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

 



Roberto Ragusa wrote:
> Dean Messing wrote:
<snip>
> > Pray tell, how did you figure this out.
> > I've re-read the man page and I don't see this
> > this differential behaviour advertised anywhere.
> 
> I just got it by testing and observing results.
> 
> Actually, the "-c" is not needed at all, it's there
> because I also want to know the total space used by backups.
> 
> And... the "-s" is also not needed! It just avoids the
> printing of all the subtotals of the subdirectories of
> your backups.
> 
> It looks like du simply discard everything already
> found on its way when calculating disk space.
> 
> Look at this:
> 
> $ mkdir d
> $ head -c 1000000 /dev/zero >f1
> $ ln d/f1 d/f2
> $ cp d/f1 d/f3
> 
> Now, this command reports only two files and not the third (hardlinked):
> 
> $ du d
> 1962    d
> 
> And, look at this; f2 is totally ignored even if it appears on the
> command line:
> 
> $ du d/f1 d/f2 d/f3
> 981     d/f1
> 981     d/f3
> 
> Amazing.

Indeed!  I just did a bit of testing like yours using multiple directories like this:
(Hope the ascii comes out on your end.)

d1       d2      d3

f1 <--> f1


f2      f2      f2  (d1/d2 and d3/f2 are linked, d2/f2 is a copy).
| <-----------> |

f3      f3 <--> f3



`du' appears (as you implied) to construct a table of what pointer to data
it's seen earlier in the arglist, and just ignore later pointers to the
same data.  As are all good solutions, it's simple and elegant (but
evidently undocumented).  Nice discovery, Roberto.


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux