[nylug-talk] logrotate question
Kristian Erik Hermansen
kristian.hermansen at gmail.com
Sat Feb 2 17:00:33 EST 2008
On Feb 2, 2008 1:47 PM, C Thala <cthala at gmail.com> wrote:
> I would like to keep the last N files. Let's say 5.
>
> Now in the past, I've written a shell script of the form,
>
> #!/bin/sh
> foocount=`ls foo*gz|wc -l`
> if [ "$foocount" -le 5 ]; then
> exit 0; # nothing needs to be deleted
> fi
> filestodelete=`expr $foocount - 5`
> rm `ls foo*gz|head -n $filestodelete`
>
> But this is ugly.
>
> I'm looking for an elegant solution.
Delete all files created more than 5 days ago?
$ find /path/to/logs -ctime +5 -type f -exec rm -f {} \;
--
Kristian Erik Hermansen
"Know something about everything and everything about something."
More information about the nylug-talk
mailing list