|
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: SamL on 18 Apr 2008 22:40 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: Ed Morton on 18 Apr 2008 22:52 On 4/18/2008 9:40 PM, 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. > 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 Regards, Ed
From: Joachim Schmitz on 19 Apr 2008 05:49 Ed Morton wrote: > On 4/18/2008 9:40 PM, 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. >> > > 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. Bye, Jojo
From: Dave B on 19 Apr 2008 06:18 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.
From: Dan Mercer on 19 Apr 2008 14:25
"Ed Morton" <morton(a)lsupcaemnt.com> wrote in message news:48095E74.1040509(a)lsupcaemnt.com... > On 4/18/2008 9:40 PM, 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. >> > > 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 You demonstrate a common misconception about find - that the format is find dir -switches ... the true format is find files ... -switches You can have multiple files and the files can be of any type - remember, a directory is just a particular type of file However, the the time values in find are days not hours. You could always use touch to touch a file with a back date - that's kind of kludgy. touch -t CCYYMMDDhhmm /tmp/touchstone if [[ $file -ot /tmp/touchstone ]] You could use perl if perl -e 'exit(!(-M "/path/to/file") > 1.0' then echo older else echo not older fi > > Regards, > > Ed > |