UNIX KORN SHELL I need to delete files older than a given date

Can someone help me modify this script to delete items older than 5/1/2011 for example?

function DeleteOldFiles
{
  LOG_LIST=`ls /usr/d/d/logs/*.*`
  for LOG_FILE in ${LOG_LIST}
  do
    echo ${LOG_FILE} >> /usr/d/d/DeleteOldFiles.log
    rm ${LOG_FILE}
  done
  echo "Finished deleting old files" >> /usr/d/d/DeleteOldFiles.log
}

DeleteOldFiles
gswitzAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
arnoldConnect With a Mentor Commented:
If you must maintain a log combine the suggestion flow01 provided
find /sr/d/d/logs -mtime +!0 | while read a; do
echo "$a" >> /usr/d/d/DeleteOldFiles.log
rm "$a"
done
0
 
flow01Commented:

I can't answer your question but I may have an alternative solution:

To remove the files older then 10 days on the determined directory you could use

find /usr/d/d/logs  -mtime +10 -exec rm {}
0
 
gswitzAuthor Commented:
On trying this, I get...
find: incomplete statement

When I remove the -exec rm {} from the end of the statement, I do get the list of files I would like to delete.

Thanks,
G
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
gswitzAuthor Commented:
My last comment was to FLOW1... Arnold, I'm trying yours now.
0
 
arnoldConnect With a Mentor Commented:
The {} has to be followed by \;

find /usr/d/d/logs  -mtime +10 -exec rm {}  \;

But you will not have a log of deleted files.
0
 
gswitzAuthor Commented:
Thanks!
0
All Courses

From novice to tech pro — start learning today.