Bob Proulx wrote:
> Géraud Meyer wrote:
>   
>> please add a `--files-from' option to du that reads a NEWLINE
>> separated list of files from a given file.  ...  P.S. Making other
>> programs of the coreutils package able to deal with NULL terminated
>> "lines" would also be nice.
>>     
>
> How this is not satisfied by using the 'xargs' program?  Could you say
> a few words about how you are trying to use this command?  Does this
> following example satisfy your needs?
>
>   head datafile | xargs -r du
>   
First the command line length is limited, which in certain cases (when
the number of files is gigantic) can make this command fail. It is the
case if someone (like me) creates lists of all the files, not just of
some directories. N.B. The -n option of xargs cannot be used to overcome
this limitation if one would like du to produce a grand total.

Second by default xargs considers any blank character a separator and
interprets certain characters, so that it must be used with still
another option: `-d \n'.
> Also you may not be aware of the new find options now available.
> POSIX defines the find "-exec command {} +" arguments now to
> efficiently process arguments to commands.  This may be used with du.
> Here is one simple example.
>
>   find . -type f -exec du {} +
>   
Thanks but the example you give has problems similar to the one above:
1) The command line may not be arbitrarily long.
2) You cannot easily filter the list after find.

And it has an additional major drawback:
3) Each time you want to run du on the list, you have to recreate the
list (which can take a lot of time).
> Bob
>   
I never said that it is impossible to use du together with other
programs. I said that the absence of the --files-from option makes it
harder by bounding the user to using non default options of almost all
the other programs, or to converting the list-file used (e.g. with ` tr
$'\n' $'\0' ') before using it with du. See the example below.

What I mean is that it makes sense and a coherent coreutils package to
also implement --files-from. Furthermore, as --files0-from is already
implemented, it should not be much work to add the almost identical
--files-from option.

Example:
$ find <dir> -<options> >files.list
    # create a NL-separated list of files
$ wc -l files.list
    # wc could not be used to count NUL-separated items
    # (another more complex program would be needed)
$ sed -i -e <expr> files.list
    # sed is designed for "regular" lines (NL-terminated)
$ wc -l files.list
$ emacs files.list
    # editing a NUL-separated list in emacs would be inconvenient
$ tr $'\n' $'\0' <files.list >files0.list
    # an additional command that I would like not to type
$ du -csb --from-files0 files0.list | tail -n1
    # note the additional tail command that also could be avoided
    # if there were an option to only display the grand total
$ IFS=$'\n' for i in `cat files.list`; do archive "$i"; done
    # if the list is not too long
    # does not work with NUL-separated lists (or I do not know how)
$ xargs -n1 -d \\n --arg-file=files.list archive
    # if the list is very long
    # here files0.list could be used

Géraud

P.S. The possibility for the --files0-from option to use the standard
input should be added to the documentation.
The info page for du mentions the fact that the --files0-from option is
useful "when the list of file names is so long that it may exceed a
command line length limitation."



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to