I want to execute stat command in my unix shell /usr/bin/ksh:
/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
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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
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 -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
date commands. Many modern Unix variants have an easy way to install GNU utilities.
perl -e '@stat = stat($ARGV); @time = localtime($stat); printf "%04d%02d%02d%02d%02d%02d\n", $time+1900, @time[4,3,2,1,0]'
Pretty sure your error is meant to indicate that your shell:
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
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: