Operating System - HP-UX
1754936 Members
1721 Online
108827 Solutions
New Discussion юеВ

Re: deleting old files by date

 
Yvette Johnson_1
Occasional Advisor

deleting old files by date

I need assistance with deleting old files (Oracle trace files) by date. I had this command to use:
find /opt/oracle/SID/bdump -type f -mtime +10
-exec rm{} \;

Of course, I want to get a listing before I remove files. When I execute this command, I don't get any results.
find /opt/oracle/SID/bdump -type f -mtime +10
-exec ls{} \;

I have files dated today, Feb/March 2004 and Dec 2003.

These command worked for me when I worked at another agency 2 years ago.

Thanks in advance for your assistance.

Yvette
13 REPLIES 13
RAC_1
Honored Contributor

Re: deleting old files by date

What user you use to find these files??
The command is OK. You wont get any files, if you do not have any rights on them.

Anil
There is no substitute to HARDWORK
Rodney Hills
Honored Contributor

Re: deleting old files by date

Do you have a space between "ls" and "{}"?

Generating a listing can be done with-
find /opt/oracle/SID/bdump -type f -mtime +10 -print

HTH

-- Rod Hills
There be dragons...
Jeff_Traigle
Honored Contributor

Re: deleting old files by date

You need a space between the command and the {}. However, for the listing, you really don't need to exec ls... find prints the found files by default anyway... unless you want to exec a long listing with ll or ls -l.
--
Jeff Traigle
Muthukumar_5
Honored Contributor

Re: deleting old files by date

You are searching and trying deleting the modified regular files (-type f ) over /opt/oracle/SID/bdump/ directory.

find /opt/oracle/SID/bdump -type f -mtime +10
-exec ls{} \; will give the modified files over within 10*24 hours limit.

Use find /opt/oracle/SID/bdump -type f -mtime +10
-exec ls -a{} \; to know more about the files informations.

what is ll -a command saying. If it is showing the files with in the duration,it will make it out.

IF you have files in ls command listing then it will delete those file(s)
Easy to suggest when don't know about the problem!
Steven E. Protter
Exalted Contributor

Re: deleting old files by date

The command is right as far as I can tell from the format of this web page.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Yvette Johnson_1
Occasional Advisor

Re: deleting old files by date

Thanks for the quick reply!

To RAC - I├в m using Oracle login. Files are owned by Oracle.

To Rodney and Jeff ├в I used the ├в print command, works!

Now, how can I make sure that my current file dated today won├в t be included when I execute the remove comm
Jeff_Traigle
Honored Contributor

Re: deleting old files by date

The -mtime +10 option you have will only exec the command you provide for files modified 10 or more days ago. Today's files would be safe. If the correct files show up in the listing with that option, then only those files would be deleted execing the rm command with it.
--
Jeff Traigle
Petr Simik_1
Valued Contributor

Re: deleting old files by date

Hi Yvette
Nice job is done by chaining -exec - it does your job your way.

Try this:

#find /opt/oracle/SID/bdump -type f -mtime +10 -exec rm{} \; -exec ls{} \;


Geoff Wild
Honored Contributor

Re: deleting old files by date

I do it like this from a script:

#!/bin/sh
#
# Geoff Wild
# April 16 2004
#
# Script to remove the old data for the PCT

# setup the log file
LOG=/tmp/pct.clean.log
if [ -f $LOG ]
then
mv $LOG $LOG.old
fi
cat /dev/null > $LOG

# setup an array of directories to search
set -A DIR "/APPL/sp/retail/poscod/report" "/APPL/sp/retail/pospass/report" "/APPL/sp/tax/cask/ib/archive" "/APPL/sp/tax/cask/ob/archive" "/APPL/sp/tax/caab/ib/archive" "/APPL/sp/tax/caab/ob/archive" "/APPL/sp/whxlinter/archive" "/APPL/sp/whxlinter/reject"

# remove files older then 31 days
for i in ${DIR[@]}
do
find $i -type f -mtime +31 -print -exec rm {} \; >>$LOG
done


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.