bug-coreutils
[Top][All Lists]
Advanced

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

Re: Feature Request: du --dir-with-slash


From: Jim Meyering
Subject: Re: Feature Request: du --dir-with-slash
Date: Mon, 10 Mar 2008 14:01:53 +0100

Thomas Guettler <address@hidden> wrote:
>>> I'm very dubious about adding this as an option.
>>> Do you really think an option is warranted for this,
>>> considering you can already get the desired behavior
>>> with a small wrapper, as I demonstrated:
>>
>> The wrapper is awkward, but it's better than a new option.
>>
>> So probably best to do nothing here as you suggest.
>
> I know that it easy to use the 'du -a' and pipe the output to a
> check if it is a directory. But if you have a lot of files, it
> really matters if you touch a files twice.
>
> And this solution does not count the size of directories.
>
> find / -xdev -printf "%k\t%p%y\n" |
> sed 's/d$/\//;t; s/.$//;' |
> LC_ALL=C sort -rn -k1,1
>
> I agree that a single letter option is maybe not needed, but a
> --dir-with-slash would be good.

If you really want this feature, yet cannot afford the
access-files-twice approach, consider processing du -a0 output
so as to transform file names like these:

  a/b/c/file
  a/b/c
  a/b
  a

into this:

  a/b/c/file
  a/b/c/
  a/b/
  a/

i.e., in iterating through names, when dirname($prev) == $name,
append a "/" to $name.

However, that would not annotate the name of an empty directory.

  $ mkdir -p a/b/c/d a/empty
  $ du -a0 a|perl -MFile::Basename -0ne 'chomp; $s=/^\d+\t(.*)/ &&
    (defined $prev ? dirname ($prev) eq $1 : 0) ? "/" : "";
    print "$_$s\n"; $prev = $1'
  0       a/empty
  0       a/b/c/d
  0       a/b/c/
  0       a/b/
  0       a/




reply via email to

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