On Tue, 30 Jul 2002, David Luff wrote:
> However, I'm totally stumped (in Cygwin) - how do I rm or grep recursively
> on a given filetype, the equivalent of the dos
>
> del /S *.o
No idea what that does! I didn't think you could do recursive
copies/deletes in DOS? ;-)
> rm -r *.o
This would delete all the files in the current directory ending in `.o'.
(the shell automatically replaces the '*.o' with the files that match).
Doing:
$ find ./ -name '*.o'
will find all the files in the current directory, and all the ones under it
ending in `.o'; for instance you might get this output:
$ find ./ -name '*.o'
foo.o
lib/moo.o
src/bar.o
You can then do something with this list once you have it (the program to
create the list, and the action to perform are different programs, which
allows them all to be simpler, and to add them together in interesting
combinations).
The `xargs' program takes the contents of stdin (data `piped' to it) and put
them on the command line, eg:
$ echo 'Hello World!' > some-file
$ cat some-file | xargs echo
Hello World!
So lets take avantage of this, and combine the three simple programs like
words in a sentance, one to locate (`find') the files; was to take them
and pass them on to the final program (`xargs'), and one to toast them `rm':
$ find ./ -name '*.o' | xargs rm
Now in your example, you wanted to grep all the files matching a particular
extension (C source files):
$ find ./ -name '*.c' | xargs grep -i Hello
(which will actual run the command something like:)
$ grep -i Hello ./foo.c ./lib/moo.c ./src/bar.c
after `xargs' has done it's magic, and `find' has found the files you're
interested in. You could always just do the following by hand:
$ grep -i Hello *.c lib/*.c src/*.c
If you get stuck, try:
$ man xargs
$ man find
Regards,
-Paul
-- Nottingham, GB-------------------------------------------------------------------- http://www.lug.org.uk http://www.linuxportal.co.uk http://www.linuxjob.co.uk http://www.linuxshop.co.uk --------------------------------------------------------------------
This archive was generated by hypermail 2.1.3 : Tue 30 Jul 2002 - 03:20:40 BST