LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to delete files in many directories? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-delete-files-in-many-directories-494811/)

pandronic 10-23-2006 05:58 AM

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

druuna 10-23-2006 06:13 AM

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.

Samoth 10-23-2006 07:41 AM

Isn't this a simpler way of doing it?

find -name \*access.log\* \*error.log\* -print -exec rm {}\;

druuna 10-23-2006 09:20 AM

@ 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 04:20 PM.