Subject: Re: Shell hack -- getting files with dates
To: Jan Danielsson <jan.m.danielsson@gmail.com>
From: Steven M. Bellovin <smb@cs.columbia.edu>
List: netbsd-users
Date: 02/04/2007 12:42:47
On Sun, 04 Feb 2007 18:29:13 +0100
Jan Danielsson <jan.m.danielsson@gmail.com> wrote:
> Steven M. Bellovin wrote:
> [---]
> > The return code from egrep is specified by Posix, as I recall.
>
> Excellent.
>
> >However
> > -- why not do
> > for f in
> > ~/backup/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].gpg
>
> The problem is that I need to process all the files, even those
> without a date -- it's just that I need to determine if they do
> contain a date, because they are handled a little differently.
>
> I have a backup in, say, /backup -- this is unencrypted -- but on an
> encrypted partition. Some files here contain dates (these are created
> twice a week), and others do not (these are created daily). For
> instance
>
> /backup
> documents.2007-01-01.tar.bz2
> documents.2007-01-04.tar.bz2
> documents.2007-01-07.tar.bz2
> documents.2007-01-10.tar.bz2
> documents.tar.bz2 <- updated (overwritten) daily
>
The shell is powerful, Luke:
for i in ~/backup/*
do
case `basename $i` in
[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].gpg) one variant
;;
*)
the other
;;
esac
done
--Steve Bellovin, http://www.cs.columbia.edu/~smb