Recusively deleting files?
Hi! Is there a command to recursively parse through a directory tree removing files? Like running rm in each folder matching wildcards. Example:
rrm * *.jpg would search all directories under current one and delete all jpgs?? Any way I can do this? I already wrote one of my own, but it doesn't work too well... |
find is pretty good for this:
find /path/to/dir -name "*.jpg" -exec rm -f {} \; |
might be better to combine the "find" and the "rm" commands in this case.
to print the names of all .jpg files recursively starting from this directory, you would use a find . -name "*.jpg" to remove all those files, you would pipe the output to "rm" like this: find . -name "*.jpg" | xargs rm (xargs just arranges for the output of "find" to be given as arguments to "rm") |
sorry, david. i didn't see your reply when i answered. i didn't mean to contradict you, only to say that using "find" is better than using a recursive "rm".
|
Ok Cool! Thanks guys! Could you just tell me what {} \; means at the end of the command????
|
Quote:
From the find man page: -exec command ; Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of `;' is encountered. The string `{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a `\\') or quoted to protect them from expansion by the shell. The command is executed in the starting directory. Regards, zakaluka |
Or... for an easier more understandable way...
rm -r directory/ rm has a "-r" switch for recursive deletion. |
Quote:
|
All times are GMT -5. The time now is 01:22 PM. |