Click to See Complete Forum and Search --> : bash script to rm files...


insanity
10-12-2002, 04:15 AM
how can i remove all the files with the extension .xxx in the folder /example and in all it's subdirs??

i try rm -fr *.xxx
it only work for the current dir

thanks!

z0mbix
10-12-2002, 06:33 AM
Originally posted by insanity
how can i remove all the files with the extension .xxx in the folder /example and in all it's subdirs??

i try rm -fr *.xxx
it only work for the current dir

thanks!

rm -rf /example/*.xxx

bwkaz
10-12-2002, 09:29 AM
for i in $(find /example -name '*.xxx') ; do rm -f $i ; done

Edit: rm -f $(find /example -name '*.xxx') will work as well, until you get more files coming back from find than rm can handle (I've seen this happen once, but I don't remember the limit). Once that happens, you start getting errors -- removing them one at a time like in the for loop works regardless of the number of files -- unless, of course, the filenames have spaces in them. Then you need to fool with the IFS variable. It's doable, but complicated.

baldguy
10-12-2002, 03:01 PM
find /example -name *.XXX -exec rm -f {} \;

insanity
10-13-2002, 03:29 AM
thx ppl:)

baldguy
10-14-2002, 08:14 PM
If you run into the limit you can always use xargs to get around that
find /example -name *.xxx -print | xargs rm