How to use stat command in solaris to get last modified time of file in a variable.
Consider my file is "abc.txt" in path /home/xyz/Desktop
How to use stat command in solaris to get last modified time of file in a variable.
Consider my file is "abc.txt" in path /home/xyz/Desktop
Maybe you have Perl:
perl -e 'print scalar((stat $ARGV[0])[9])' /home/xyz/Desktop/abc.txt
1394183519
The answer is in seconds since the Epoch.
Or into a variable:
var=$(perl 'print scalar((stat $ARGV[0])[9])' /home/xyz/Desktop/abc.txt)
If you want human-readable:
perl -MPOSIX -e 'print POSIX::strftime "%d/%m/%Y\n", localtime((stat $ARGV[0])[9])' yourfile
07/03/2014
ls -l
will show the last modified time. If you have a recent Solaris release, you can use the stat
command to get a more detailed view:
# ls -l abc.txt -rw-r--r-- 1 root root 29 Mar 7 09:45 abc.txt # stat abc.txt File: `abc.txt' Size: 29 Blocks: 2 IO Block: 8192 regular file Device: 3240001h/52690945d Inode: 64859 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2014-03-07 09:44:37.006708000 +0000 Modify: 2014-03-07 09:45:50.226502000 +0000 Change: 2014-03-07 09:46:25.869958000 +0000 # cat /etc/release Oracle Solaris 11.1 X86 Copyright (c) 1983, 2012, Oracle and/or its affiliates. All rights reserved. Assembled 19 September 2012
If your Solaris release doesn't have the stat
command available, you can use that hack:
# truss -f -v 'lstat,lstat64' ls -d abc.txt 2>&1 | grep "mt =" 612: mt = Mar 7 09:46:57 CET 2014 [ 1394182017.056711000 ]