How to delete files in many directories?
I want to delete all the access.log and error.log from my logs directory. The problem is there are a lot of domains, each with its own directory and I have to go into each one and delete the files. Is there a way to delete all this files with just one command?
Thank you |
Hi,
The find command can help you: find . \( -name "access.log" -o -name "error.log" \) -print This will look for access.log files and error.log files from the dir you are in and all its subdirs. If you want to delete them this can be done by doing one of the following: find . \( -name "access.log" -o -name "error.log" \) -print | xargs rm or find . \( -name "access.log" -o -name "error.log" \) -exec rm {} \; Hope this helps. |
Isn't this a simpler way of doing it?
find -name \*access.log\* \*error.log\* -print -exec rm {}\; |
@ Samoth:
find -name \*access.log\* \*error.log\* -print -exec rm {}\; This does'nt work on my box. There's no starting point (. or /whatever) and the -name construct also doesn't. The last part could be version related (tried it at home: GNU find version 4.1.20 and on sunOS5.9, don't know the find version of that one). |
All times are GMT -5. The time now is 03:36 PM. |