12 July 2006

xargs and find

find /srv/files -name "Thumbs.db*" -print0 | xargs -0 /bin/rm -f {}

This deletes all files matching pattern Thumbs.db*. -print0 and -0 cause delimitation by the null char rather than whitespace, so filenames can contain whitespace.

If you add -i to the xargs options the command will be called once for each entry rather than receiving a list of entries, e.g :

find . -name "${pattern}" -print0 | xargs -0 -i convert -verbose -quality ${compression} {} {}

Note, with -i {} can be repeated multiple times in-place of the entry.