I want to execute stat command in my unix shell /usr/bin/ksh:
Input:
/bin/date +%Y%m%d%H%M%S -d "$(/usr/bin/stat -c %x find.txt)"
And the output:
/usr/bin/ksh: stat: not found
My system:
SunOS 5.10 Generic_150400-23 sun4v sparc sun4v
kshsolarisstat
I want to execute stat command in my unix shell /usr/bin/ksh:
Input:
/bin/date +%Y%m%d%H%M%S -d "$(/usr/bin/stat -c %x find.txt)"
And the output:
/usr/bin/ksh: stat: not found
My system:
SunOS 5.10 Generic_150400-23 sun4v sparc sun4v
Best Answer
The
stat
command is not standard. There's one on Linux, a more restricted one on embedded Linux, one with completely different options on FreeBSD and OSX, and none on most other Unix variants such as Solaris, AIX, and HP-UX. Your syntax looks like it's intended for Linux'sstat
.You're apparently running a system without
stat
. You probably don't havedate -d
either then.The only portable way to list a file's access time is with
ls
.This gives less precise output that what you need, in a cumbersome format.
If you can install GNU coreutils, do so and use its
stat
anddate
commands. Many modern Unix variants have an easy way to install GNU utilities.Alternatively, use Perl, which is very often installed on Unix systems. Call
stat
to read the file's timestamp andlocaltime
to break the timestamp into date and time parts.