[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: |
Sun, 9 Jun 2019 22:51:51 +0200 |
User-agent: |
Mutt/1.12.0 (2019-05-25) |
On Sun, Jun 09, 2019 at 03:32:07PM -0500, Peng Yu wrote:
> Hi,
>
> I don't find a bash native way to test if a file is older than a
> certain period of time. Is there not a native way to do so? Thanks.
>
> https://www.unix.com/shell-programming-and-scripting/101115-bash-condition-file-older-than-1-hour.html
>
> --
> Regards,
> Peng
There is the -nt ("newer than") test, but that needs a reference file to
test against. You could create such a file with the touch utility.
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.
--
Kusalananda
Sweden