[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] bash native way to support test file is older than a cer
From: |
Andreas Kusalananda Kähäri |
Subject: |
Re: [Help-bash] bash native way to support test file is older than a certain period of time |
Date: |
Mon, 10 Jun 2019 15:57:44 +0200 |
User-agent: |
Mutt/1.12.0 (2019-05-25) |
On Mon, Jun 10, 2019 at 09:06:57AM -0400, Greg Wooledge wrote:
> On Sun, Jun 09, 2019 at 10:51:51PM +0200, Andreas Kusalananda Kähäri wrote:
> > The other alternative is to use find:
> >
> > if [ -n "$( find "$myfile" -mmin +60 -print)" ]; then
> > echo file was modified more than 60 minutes ago
> > fi
> >
> > (where "$myfile" is some path to a file)
> >
> > There's nothing "bash native" about that though, but it would be
> > portable.
>
> Portable to any system with GNU find, you mean (the -mmin test isn't
> standard). It also assumes the filename is not just one or more newline
> characters, but that might be getting a little bit too pedantic.
You are correct, the "-mmin" predicate is not standard, that was
me being careless. Although it _is_ supported in other find
implementations than GNU find.
For the other issue, one could use "-exec echo x \;" instead of
"-print", or anything that outputs something that isn't stripped off by
the command substitution (maybe "-ls" if that's implemented).
However, it looks a bit awkward to do this on a single file. It wasn't
stated in the question what the workflow looks like, but if something is
to be done to _all_ files older/newer than an hour, this would probably
be better done through "find ... -mmin +60 -exec ... {} +". But that's
not really related to bash.
... or one could use a zsh glob with a "(mh+1)" glob qualifier...
--
Kusalananda
Sweden