Notices


Reply
Thread Tools
Posts: 147 | Thanked: 12 times | Joined on Aug 2007 @ Washington State
#1
Is it possible for a shell script to get the modification date of a file? How?
 
Posts: 118 | Thanked: 26 times | Joined on Feb 2008
#2
stat should be your friend...

filename=foo
date=`stat -c '%y' $filename`

or, to get seconds since epoch (more machine usable)
date=`stat -c '%y' $filename`


man stat on a your friendly neighborhood Linux machine will tell you more. Unfortunately, for some reason, stat isn't installed by default on the N8x0...

Martin
 
Posts: 118 | Thanked: 26 times | Joined on Feb 2008
#3
Ok, seems like "perl" is installed by default...

sooo.... why don't you use perl? It has a built-in stat command and should run faster for any reasonably sized script.

However, if you really want to avoid perl, you can use this in your shell script:

Code:
filename=foo
date=`perl -e 'print ((stat($ARGV[0]))[9] . "\n")' $filename`
(this will give you seconds since epoch)

for more friendly output:

Code:
filename=foo
date=`perl -e 'print (localtime((stat($ARGV[0]))[9]) . "\n")' $filename`

Hope that helps.

Martin
 

The Following User Says Thank You to m_stolle For This Useful Post:
Posts: 147 | Thanked: 12 times | Joined on Aug 2007 @ Washington State
#4
Nice try, but as far as I can tell, stat is not even available.

Edit: Just read your second post. I may have to give that a try. Thanks.
 
Posts: 147 | Thanked: 12 times | Joined on Aug 2007 @ Washington State
#5
Perl to the rescue! I love perl.
 
Reply


 
Forum Jump


All times are GMT. The time now is 09:50.