Friday, October 24, 2008

remove files in different directories

I used to know how to find files in different directories,
find . -name '*.raw' will list all the raw files, but how to delete them?

Here is the result:


[root@QSLENG13_FC5 xxx]# find . -name '*.raw' -exec ls {} \;
./SP-MIDI/output_midi.raw
./SMAF_MA-5/output_midi.raw
./SMAF_MA-3/output_midi.raw
./SMAF_MA-2/output_midi.raw
./MXMF/output_midi.raw
./MIDI_RIFF_Format_1/output_midi.raw
./MIDI_RIFF_Format_0/output_midi.raw
./MIDI_Format_1/output_midi.raw
./MIDI_Format_0/output_midi.raw
./KAR/output_midi.raw
./JTS/output_midi.raw
./iMelody/output_midi.raw
[root@QSLENG13_FC5 xxx]# find . -name '*.raw' -exec rm {} \;
[root@QSLENG13_FC5 xxx]# find . -name '*.raw' -exec ls {} \;


Another usage: I want remove GNU assembly code which is generated by ADS and all the other object files.


# find . \( -name '*.o.s' -o -name '*.o' \) -exec rm {} \;


or using "-ok" with control by the user (type 'y' or 'n' for each file).

[root@QSLENG13_FC5 linux]# find . \( -name '*.a' -o -name '*.so' \) -ok rm {} \;
< rm ... ./libmqcore32.a > ? n
< rm ... ./libmqcore32.so > ? n
< rm ... ./libq3di32.so > ? n
< rm ... ./libq3di32.a > ? n