Operating System - HP-UX
1834213 Members
2402 Online
110066 Solutions
New Discussion

Removing files from a directory

 
SOLVED
Go to solution
Balaji_6
Advisor

Removing files from a directory

Hello,

I have a Oracle database server and there is a directory with a log files updating regularly.I just want to search those files in with the date-wise and need to delete the logfiles files morethan 20 days old files.
And this is going to run as a cron daemon,this is part is perfect.

Please provide me a logic to solve the above issue.
If anything require more. please let me know.

Thanks & Regards
Balaji
THE WORD IMPOSSIBLE ITSELF SAYS I'MPOSSIBLE
3 REPLIES 3
T G Manikandan
Honored Contributor
Solution

Re: Removing files from a directory

balaji,

When you mean the log files are they archive log files or the oracle trace log files.

Make sure and think twice that those files are not needed.

you can just do a

#find -type f -name -mtime +20 -print
list them


#find -type f -name "*.log" -mtime +20 -exec ll {} \;

Remove
#find -type f -name "*.log" -mtime +20 -exec rm {} \;
Robert-Jan Goossens
Honored Contributor

Re: Removing files from a directory

Hi Balaji,

The first is to list the files in the directory, the second to remove the files.

# find /your_dir -mtime +20 -exec ls -l {} \;

# find /your_dir -mtime +20 -exec rm {} \;

Hope this helps,
Robert-Jan.
Alex Ostapenko
Advisor

Re: Removing files from a directory

Also, you can see the files in reverse chronological order (date-wise) with the command "ls -lt | more" (lower case ell and lower case t).
=:-) Alex