|
Prev: china wholesale cheap nike shoes,cheap nike,cheap nikes,nike jordans sneaker's,cheap nike air force 1s
Next: hay can you remove this post please it was a mistake thank you i was kind of desperate
From: mop2 on 19 Apr 2008 17:40 For a given file: [ $(($(date +%s)-$(date -r file +%s))) -ge 3600 ]&&echo old SamL wrote: > I am looking for a simple way to test if a file is more than one hour > old in ksh. I think 'find' command may be able to do that but I do not > know the detail. Any help? Thanks.
From: Dave Kelly on 19 Apr 2008 19:01 On Apr 19, 4:40 pm, mop2 <mop2bky4mz5tyjwa8ersp7hrg5u...(a)gmail.com> wrote: > For a given file: > > [ $(($(date +%s)-$(date -r file +%s))) -ge 3600 ]&&echo old > > SamL wrote: > > I am looking for a simple way to test if a file is more than one hour > > old in ksh. I think 'find' command may be able to do that but I do not > > know the detail. Any help? Thanks. Depending where the files exist. My manual says 'lynx' will open local files. See if information in this script snippet will help. LDPTIME=$(date -d "`lynx -dump http://www.tldp.org/timestamp.txt`" + %s) TIMESTAMP=$(date -d "`lynx -error_file=lynx_error -dump - connect_timeout=20 $url/timestamp.txt`" +%s) if [ "$TIMESTAMP" == "" ] ; then continue fi TIMEFRAME=$(($LDPTIME - $TIMESTAMP)) printf "Time frame is %s minus %s equal %s\n" "$LDPTIME" "$TIMESTAMP" "$TIMEFRAME" if [ "$TIMEFRAME" -gt 1209600 ] ; then
From: SamL on 19 Apr 2008 22:46 On Apr 19, 6:18 am, Dave B <da...(a)addr.invalid> wrote: > On Saturday 19 April 2008 11:49, Joachim Schmitz wrote: > > >> If by "old" you mean how long has it been since it was created, you > >> can't (unless you save the information yourself) as UNIX doesn't > >> store file creation time. If you mean how long since it was last > >> modified, what you probably are looking for is: > > >> find . -maxdepth 1 -ctime +1 -name file > > But that's days, not hours. > > Then I guess we need some math: > > if [ $(( $(date +%s) - $(stat -c %Z file) )) -gt 3600 ]; then > ... > fi > > (or %Y instead of %Z if we want the modification time) > > Or, with GNU find (adapted from Ed's): > > find . -maxdepth 1 -cmin +60 -name file > > (or -mmin if we want the modification time), and test if the command outputs > something. > > All the above solutions need GNU tools. Not sure whether standard methods > exist for doing the same thing. > > -- > D. I am using AIX and unfortunately do not have the stat command, so I tried the find command approach. It essentially works. Only one thing, it will return 0 even if there is no files found satisfying the criteria. So find . -maxdepth 1 -cmin +60 -name file >/tmp.$$ [[ -s /tmp.$$ ]] && echo "old" Thanks to all those who replied.
From: Stephane CHAZELAS on 20 Apr 2008 05:26 2008-04-18, 19:40(-07), SamL: > I am looking for a simple way to test if a file is more than one hour > old in ksh. I think 'find' command may be able to do that but I do not > know the detail. Any help? Thanks. If you're implementation of ksh is zsh's, *(mh+1) expands to the list of files that are more than 1 hour old. -- St�phane
From: Dave B on 20 Apr 2008 06:21
On Saturday 19 April 2008 20:25, Dan Mercer wrote: >> time. If you mean how long since it was last modified, what you probably >> are looking for is: >> >> find . -maxdepth 1 -ctime +1 -name file > > You demonstrate a common misconception about find - that the format is > > find dir -switches ... > > the true format is > > find files ... -switches Where did you read that? From the standard man page: find [ -H | -L ] path ... [ operand_expression ... ] -- D. |