Move/copy/delete/ all these … 📁
What happens when you find
10.000 results ? What you’re going to use exec
or xargs
?
The answer is dead simple, always xargs
. When using -exec
you run a separate instance of the called program for each element of input and when xargs
is being used you are bundling/collecting the input and execute the command as few times as possible which is usually just once.
Side notes:
The
xargs
command in UNIX is mainly used when building an execution pipeline from STDIN. Tools likegrep
can accept STDIN as a parameter, but usingxargs
allows tools likerm,echo,mkdir
accept to accept STDIN as arguments.
find <> -exec <command> {} \;
execute command; true if 0 status is returned. all of the following arguments to find are taken to be arguments to the command until an argument consisting of;
is encountered. The string{}
is replaced by the current file name being processed everywhere it occurs in the arguments to the command.