On Wed, Oct 09, 2019 at 03:46:20PM +1100, Craig Sanders wrote:
> BTW, you could then pipe the output of the above pipeline into xargs to do
> something with the filename(s) matched. e.g. to move the matching file to
> another directory:
>
> xargs -0r mv -T /destination/
Actually, that should be:
xargs -0r mv -T /destination/ --
The "--" prevents any filenames from being misinterpreted as options, in case
any of them begin with a "-".
This, for example, prevents catastrophes like:
touch "-rf"
rm *
or:
find .... -print0 | xargs -0r rm
Which brings up one of the main reasons for using NUL separators when dealing
with filenames - just like using "--", it is good, defensive-programming
best-practice. It prevents the problems that would happen if you forgot or
didn't realise that there are files with annoying filenames.
The directory you're working with right now might not have any such filenames,
but it's still a good habit to write your one-liners and scripts defensively
because you will probably re-use it later.
craig
--
craig sanders <[email protected]>
_______________________________________________
luv-main mailing list
[email protected]
https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main