bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need to delete files that have a timestamp on its name


From: Bob Proulx
Subject: Re: Need to delete files that have a timestamp on its name
Date: Mon, 9 Oct 2006 10:09:55 -0600
User-agent: Mutt/1.5.9i

ozwolverine wrote:
> I hava a cron that generates a backup with a name like:
> backup_jboss-4.0.3_09102006.tar.gz, it gets generated once a week, every
> friday, I need that after the cron creates the new weekly backup to delete
> the others and I want just to leave in the system the last one, how could I
> do that? How do the regular expression to delete the old backups should look
> like?

Your question is really about basic shell programming and not specific
to bash.  It would probably be better answered in a forum specializing
in shell programming rather than in the bug-bash mailing list which
specializes in bash specific issues.

But having said that, here is a suggestion.  I did not test this but
just typed it in off the top of my head.

Because you know that the filename does not have any spaces or other
characters that would match the shell's IFS or meta-characters and
would be unlikely to overflow ARG_MAX I would probably do something
simple.

  #!/bin/sh
  list=$(ls -1dr /tmp/backup_jbos-?.?.?_????????.tar.gz 2>/dev/null | sed 1d)
  if [ -n "$list" ]; then
      rm -rf $list
  fi

This is very simple and easy for people who follow you looking at the
script to understand and so I would probably stop there.  It is not
perfect but probably good enough.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]