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
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
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's stat
.
You're apparently running a system without stat
. You probably don't have date -d
either then.
The only portable way to list a file's access time is with ls
.
ls -log -u find.txt
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
and date
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 and localtime
to break the timestamp into date and time parts.
perl -e '@stat = stat($ARGV[0]); @time = localtime($stat[9]); printf "%04d%02d%02d%02d%02d%02d\n", $time[5]+1900, @time[4,3,2,1,0]'
Pretty sure your error is meant to indicate that your shell:
/usr/bin/ksh:
Can't find "stat":
stat: not found
Does your operating system provide the "stat" command? You'll need to provide more information on your operating system and it's version for further guidance.
You may also have a problem in your "PATH" environment variable.
It depends completely on your system, which you did not specify. An alternative to installing the binary provided by your package manager is to compile the program from source. To do so, you must first download the coreutils source (coreutils-8.0
at the time of writing).
If it is in an archive, unarchive it and then enter into the directory of the source. Run the configure script with the command ./configure
, and then wait for it to finish. After configure has completed (with no major errors), then run make, with the command make
.
The time it takes for make to complete can be anywhere from 30 seconds to literally days, depending on the size and complexity of the application. In this case however, it is highly unlikely for the make step to take over a few minutes.
Once make is done compiling the programs (without errors), install the programs with the command make install
, or if you are not the root user sudo make install
. This should only take a few seconds, although in some cases it can take longer. Once completed, you can exit the coreutils
directory, and then proceed to delete it.
./configure && make && make install
.For more information, see these pages:
stat
isn't installed ? It's normally part of thecoreutils
package. – steve Jun 01 '16 at 20:09ls
. For examplels -siv -@ -/ c -%all z
displays file creation time, time stamps, access, etc. Solaris-specificls
is a powerful tool, and it essentially replacesstat
, along with many other basic commands. – Jun 01 '16 at 23:19