Link to home
Start Free TrialLog in
Avatar of gswitz
gswitz

asked on

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
Avatar of flow01
flow01
Flag of Netherlands image


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 {}
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gswitz
gswitz

ASKER

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
Avatar of gswitz

ASKER

My last comment was to FLOW1... Arnold, I'm trying yours now.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gswitz

ASKER

Thanks!