LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 05-08-2008, 05:12 AM   #1
irfanb146
LQ Newbie
 
Registered: Mar 2008
Posts: 19

Rep: Reputation: 0
removing directory having file older than 4 days


Hi,

I got directory of Oracle Archive log, in this directory whenever any archive log created, the new directory by the name of date is creted and the file is creted inside it, so i need to perform daily delete of archivelog files, what i do is i remove the folder by using following

rm -r <name of folder e.g. 2008-05-02>

but i want to autmate the deletion, for this i am finding older file then execute the remove but by the following line only files will be removed directories will not be removed, kindly help me in removing the parent directory of archive logfiles

find /home/u01/app/oracle/flash_recovery_area/test1/archivelog -name "*.arc" -mtime +4 -exec rm {} \;
 
Old 05-08-2008, 05:45 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
The archive directories should have the modification time of the last created log file (that is the last new entry in the directory itself). If this is the case you can find directories based on modification time and remove them at once:
Code:
find /path -type d -exec echo rm -r {} \;
Otherwise, following your example you can extract the name of the parent directory by the dirname command, then pipe the output to uniq (to remove duplicates if multiple files are inside the same directory) and finally remove directories passing arguments through xargs:
Code:
find /path -name "*.arc" -mtime +4 -exec dirname {} \; | uniq | xargs echo rm -r
Anyway, since the directory names are based on the creation date, you can remove them accordingly. For example by the command:
Code:
echo rm -r /path/$(date -d "today -4 days" +"%Y-%m-%d")
In all the above example I put an echo statement before the rm command for testing purposes. When you are satisfied with the result you can strip out the echo command and safely remove the directories. Also I used /path instead of the actual path to make the commands more readable.

Hope this helps. Cheers!

Last edited by colucix; 05-08-2008 at 05:49 AM.
 
Old 05-08-2008, 06:53 AM   #3
irfanb146
LQ Newbie
 
Registered: Mar 2008
Posts: 19

Original Poster
Rep: Reputation: 0
Thank you for your help, I act on advice and it is working fine
 
Old 05-08-2008, 09:07 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
You're welcome! Just out of curiosity, which of the above mentioned solutions did you adopt?
 
Old 05-08-2008, 12:05 PM   #5
irfanb146
LQ Newbie
 
Registered: Mar 2008
Posts: 19

Original Poster
Rep: Reputation: 0
Second one
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Removing File and Directory Paris Heng Linux - Newbie 5 02-20-2008 07:19 AM
Delete files older then 30 days stefaandk *BSD 1 01-07-2008 09:31 PM
removing logs older than 30 days linuxN3w8ie Linux - Newbie 3 11-21-2006 02:27 PM
How to move files older than 30 days gfem AIX 8 11-08-2006 05:58 AM
delete files older than 30 days using cronjob latheesan Linux - Newbie 5 06-14-2005 03:40 PM

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

All times are GMT -5. The time now is 10:20 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration