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: Thu, 06 Mar 2008 15:40:06 +0100

Thomas Guettler <address@hidden> wrote:
> I use "du -ax / | sort -rn > /var/tmp/du-`date --iso`" to get the sorted
> total size of all
> files and directories.
>
> Unfortunately you can't see a difference between a directory and a file
> in the output. It would be nice if the directories would be added by a
> slash.
>
> Example:
>
> old:
> 307704984       /
> 291330280       /home
>
> new:
> 307704984       /
> 291330280       /home/
>
> This way you can see if a line is a directory or not. This is even more
> important
> if you want to use the output for a script.
>
> I suggest 'du --dir-with-slash' or 'du --trailing-slash' as parameter.

Thanks for the suggestion, but rather than adding an option,
how about wrapping a small script around du?
Use du's --zero (-0) option to make it work even with
names containing newline:

mkdir j && cd j && touch a b && mkdir d d2 &&
  du -a -0|perl -0 -ne \
    'chomp; /^\d+\t(.*)/ and print "$_", (-d $1 ? "/" : ""), "\n"'

0       ./d2/
0       ./d/
0       ./b
0       ./a
0       ./

Of course, that will convert "/" to "//", but it's just a one-liner, too.
I'm sure you can adapt.




reply via email to

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