LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-23-2006, 05:58 AM   #1
pandronic
LQ Newbie
 
Registered: Oct 2004
Posts: 2

Rep: Reputation: 0
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
 
Old 10-23-2006, 06:13 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 10-23-2006, 07:41 AM   #3
Samoth
Member
 
Registered: Apr 2005
Distribution: Exherbo
Posts: 474
Blog Entries: 1

Rep: Reputation: 32
Isn't this a simpler way of doing it?

find -name \*access.log\* \*error.log\* -print -exec rm {}\;
 
Old 10-23-2006, 09:20 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
@ 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).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to delete directories with files using command line FTP Zombie13 Linux - Software 2 03-10-2006 10:23 PM
how to search for and delete empty directories? BrianK Programming 4 06-03-2005 07:24 AM
How can i delete Directories and Subdirectories? OrganicX Linux - Newbie 15 03-05-2003 08:48 PM
How does one delete directories with content as the SU? Ferrell Ramey Linux - General 2 08-22-2002 07:16 PM
Cant delete directories/files skopje909 Linux - General 2 11-07-2001 05:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration