I have two files. I need to calculate the timestamp difference between the two files.
I need the timestamp difference between test1 and test2: -rw-r--r-- 1 root root 1 Aug 16 16:26 test1 -rw-r--r-- 1 root root 2 Dec 13 2010 test2
I need the timestamp difference between test3 and test4.
-rw-r--r-- 1 root root 3 Aug 16 16:26 test3
-rw-r--r-- 1 root root 4 Aug 16 17:34 test4
Please let me know how we can achieve it in Solaris . I am using Solaris and my machine info is :
- Sol 5.10 Generic_127128-11 i86pc i386 i86pc.
If you need to know anything else please let me know.
I have got the below answer date conversion to seconds in Solaris.
truss 开发者_JS百科/usr/bin/date 2>&1 | grep ^time | awk -F"= " '{print $2}'
but this is for the current date .. how we can do it for file (for example test3, as above)?
The stat(1) command can show the time stamp in seconds-since-epoch:
stat --printf '%Y\n' foo
Thus something like the following might work:
(stat --printf '%Y' test2; printf ' - '; stat --printf '%Y\n' test4) | bc -lq
Tweak as required.
Try something like this to get the date in seconds
date +%s -d "`ls -l test1 | awk -F " " '{ print $6,$7 }'`"
$ ls -l .bashrc*
-rw-r--r-- 1 max max 360 Dec 14 2010 .bashrc
-rw-r--r-- 1 max max 359 Dec 2 2010 .bashrc~
$ echo $((`stat --format=%Y .bashrc` - `stat --format=%Y .bashrc~`))
1018884
The $(())
syntax is bash arithmetic expression expansion. What happens above is that file timestamps in seconds since Unix epoch get subtracted and the difference is printed.
精彩评论