Angus Lees wrote:

> the problem with this (esp in this case) is that the command line is
> quite likely to get too long, so you use xargs(1):
> 
>  find . -type f -print | xargs md5sum > md5.list

I'd suggest a small improvement to this. When used as above, find puts
newlines between filenames while xargs splits the input stream at any
blank, including newline. Filenames are permitted to contain any kind of
blank (space, tab, NL, FF, CR). In the (perhaps unlikely) event that one
or more filenames contain blanks, xargs will split the filename list
incorrectly and therefore pass incorrect filenames to md5sum. Gnu find
and xargs both have specific arguments for dealing with this:

        find . -type f -print0 | xargs -0 md5sum > md5.list

The -print0 argument to find causes it to put nulls between filenames
(instead of newlines). The -0 (or --null) argument to xargs tells it to
split at nulls instead of blanks. Filenames cannot contain nulls. This
will therefore work correctly regardless of what the files are actually
called.

- Raz


--
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug

Reply via email to