Mailinglist Archive: opensuse (1476 mails)

< Previous Next >
Re: [opensuse] How to delete everything but the newest 5 files?
  • From: Anders Johansson <ajh@xxxxxxxx>
  • Date: Sat, 31 Mar 2012 20:48:29 +0200
  • Message-id: <1989957.yLBbGqYkun@carolin>
On Saturday 31 March 2012 20:06:30 Andreas wrote:

I'd like to let cron clean up a directory that holds hourly backups.
So there are 24 new files every day.

I'd need some scripting that sorts the content of this directory and
then removes everything but the 5 newest files.

Is there a howto or even sample code that does this?

logrotate already does pretty much just that. As the name suggests, it is
intended for log files, but there is nothing to say it couldn't be used for
other types of files as well. If you're careful with the config file, it can
be used for pretty much any situation where you have a regular input of files
and you only want to keep the last few of them

To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >