Difference between revisions of "Find notes"

From Noah.org
Jump to navigationJump to search
(New page: Category:Engineering You see some people pipe find output into xargs, but other people start a command using -exec. You wonder what the difference is. The difference is that xargs is f...)
 
Line 4: Line 4:
 
arguments and feed batches to the subcommand, so it doesn't have to start a new instance of the subcommand for every argument.
 
arguments and feed batches to the subcommand, so it doesn't have to start a new instance of the subcommand for every argument.
  
Generally I find -exec easier to use because you can easily repeat the found filename in the exec argument.
+
Generally I find -exec easier to use because you can easily repeat the found filename in the exec argument. It's easier for me to express exactly what I want to be executed.
 +
Of course, some people think the find syntax is wacky.  
 
The xargs command comes in handy in other places such as a stream not generated by find, but when using
 
The xargs command comes in handy in other places such as a stream not generated by find, but when using
 
find I stick with -exec unless I have a good reason not to.
 
find I stick with -exec unless I have a good reason not to.
 +
 +
You can always do it in a shell loop too:
 +
  for filename in *.png ; do convert $filename `basename $filename .png`.jpg; done

Revision as of 18:51, 6 June 2007

You see some people pipe find output into xargs, but other people start a command using -exec. You wonder what the difference is. The difference is that xargs is faster. It will intelligently group arguments and feed batches to the subcommand, so it doesn't have to start a new instance of the subcommand for every argument.

Generally I find -exec easier to use because you can easily repeat the found filename in the exec argument. It's easier for me to express exactly what I want to be executed. Of course, some people think the find syntax is wacky. The xargs command comes in handy in other places such as a stream not generated by find, but when using find I stick with -exec unless I have a good reason not to.

You can always do it in a shell loop too:

 for filename in *.png ; do convert $filename `basename $filename .png`.jpg; done