Differences between revisions 2 and 3
Revision 2 as of 2002-05-28 11:57:43
Size: 838
Editor: SimonHuggins
Comment:
Revision 3 as of 2008-02-19 15:39:23
Size: 838
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

CategoryComputingTips > FileUtilsCompTips

FileUtils Tips

Using find

  • find is really useful and once you get the hang of it you probably want to use the -exec thing but this it isn't hugely clear that you have to escape the terminating ; from the shell. You use {} to substitute for the name of the file found.

find . -name '*.c' -exec echo foo {} \;
  • You can also use xargs for this to save spawning one process for each file.

find . -name '*.c'|xargs grep foobar
  • When your filenames have spaces in and you want to use find and xargs together use the -print0 and -0 flags to null terminate the strings find passes to xargs and conversely so xargs knows it's gettings null terminated input.

find . -name '*.c' -print0|xargs -0 grep foobar

TheEarthWiki: FileUtilsCompTips (last edited 2008-02-19 15:39:23 by localhost)