How to search and delete files in Unix/Linux
I would like to recursively delete files of type *.txt inside a directory (and its subdirectory and so on). How do I do thaT?
I tried rm -rf 'find . -name *.txt" but this doesn't work. |
Try:
Code:
find . -name '*.txt' -exec rm '{}' ';' |
Try find . -iname *.txt -exec rm -f {} \;
Håkan Edit: Ahh, you beat me to it. :) |
'I would like to recursively delete files of type *.txt inside a directory (and its subdirectory and so on). How do I do thaT?
I tried rm -rf 'find . -name *.txt"' You are on the right track. Try it this way: find /home/user/sampdir -iname "*.txt" -exec rm {} \; ___________________________________ Be prepared. Create a LifeBoat CD. http://users.rcn.com/srstites/LifeBo...home.page.html Steve Stites |
A little explanation would be helpful. I get the '-exec rm' part but what are the two switches after that??
{} \; ?? |
"A little explanation would be helpful. I get the '-exec rm' part but what are the two switches after that??"
{} \; The {} tells find to drop each file name that is a match to the pattern into the rm command and then execute the rm command. The \; is necessary for bash to understand the syntax. The return is used by bash as "end of command". In this command you need two "end of commands" in a row (or nested "end of commands" ) or bash will get confused. The first "end of command" is the \; and the second is the return. See: man find ___________________________________ Be prepared. Create a LifeBoat CD. http://users.rcn.com/srstites/LifeBo...home.page.html Steve Stites |
All times are GMT -5. The time now is 11:24 PM. |