On 4/5/06, jhuniepi <[EMAIL PROTECTED]> wrote:
> hello to all,
>
> in a directory there are list of files. /dir1/sub1/*
> i want to move those files in /dir1/sub1/* to /dir1/sub2/*,
> only if the file in /dir1/sub1/ is ten minutes older or more than the
> current datetime.
>
> i created a script but my problem is how do i know if file timestamp
> is older than the current datetime. it's like this: current datetime -
> file timestamp. how to do that in bash script?

Using stat and data commands:

date +%s --> epoch seconds from present date
stat -c %Y $file --> epoch seconds of target file

You can expand more from this:

x-- begin snip --x

test $(expr `date +%s` - `stat -c %Y $file`) -ge 600\
    && echo "$file modified more than 10 mins ago"

x-- end snip --x

Or if you like to use `find`:

x-- begin snip --x

if [ "`find $FILE -mmin +10`" ]
then
    echo "$FILE is more than 10 minutes old"
else
    echo "$FILE is a youngster"
fi

x-- end snip --x

Hope this helps.

--
Jed R. Mallen
GPG key ID: 81E575A3 fp: 4E1E CBA5 7E6A 2F8B 8756  660A E54C 39D6 81E5 75A3
http://jed.sitesled.com
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
plug@lists.linux.org.ph (#PLUG @ irc.free.net.ph)
Read the Guidelines: http://linux.org.ph/lists
Searchable Archives: http://archives.free.net.ph

Reply via email to