You can use find to do this, provided that you know the number of days before which you want files deleted, using the -mtime +<No. of days> option, for example, to delete those files last modified more than 30 days ago:
find /<path to files> -mtime +30 -exec rm {} \;
Note that it is good practice to issue a -print command before executing the rm option, just to make sure that you're picking up only the files you want to delete and no others:
Hi Aimee find is you friend :
find curr_dir -name "*filename*" -mdate +350
will find files whose names are like 'filename' and are older than 350 days, in the current directory and all directories below it.
When you're happy you've got the correct file selection,
issue the same command with -exec rm {} \; after it, to delete 'em find curr_dir -name "*filename*" -mdate +350 -exec rm {} \;
According to your requirement, I think that you wanted to remove the files according to the timestamp. Just wrote a simple script for you. If the script work, then you remove the '#' before command 'rm'.
for i in `ls -1 *.log`
do
logfile=`ls -l $i | awk '{print $6,$7,$9}'`
if [[ ${logfile% *} = 'Jan 1' ]];
then
echo "Removing ${logfile##* }"
#rm ${logfile##* }
else
echo "Fail to remove ${logfile##* }"
fi
done
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.