Piping the output of find into a new command (find, xargs)

Last modified on July 24, 2026 • 1 min read • 103 words
E.g.
E.g. to change the permissions of all directories:find . -type d -print | xargs /bin/chmod ug+rxTo be able to handle directory names with special charactersfind . -type d -print0 | xargs -0 /bin/chmod ug+rxIn order to find all tif files in the current directory or below and to compress them (using the ImageMagick “mogrify” command and LZW compression):find . -name '*.tif' -print | xargs mogrify -compress LZWApart from the “xargs” method, some command (including find) accept the “-exec” argument. The following finds all files in the current directory that are smaller than 4k and deletes them:find . -size -4k -exec rm {} \;