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