Solaris / OpenSolarisThis forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
(Well, by "Gurus" I mean everyone out here looking at this question.)
I, in a separate post here, asked how to check the "file creation time" and not just the "change/modification/access times". Somebody did a good job and gave pointers to resources that explain that if we run "stat" command on an ext4 filesystem then we may get this information as it will appear in the last line "crtime" meaning the birth date of a file.
Well, out of curiosity I hit the command "stat fileName" on my Solaris 10 OS / OpenSolaris as well. But it screamed out: "Command not found".
So, I need this "stat" command which I use on Linux flavours without any issue. How to get it on Solaris?
int stat(const char *restrict path, struct stat *restrict buf);
int lstat(const char *restrict path, struct stat *restrict buf);
int fstat(int fildes, struct stat *buf);
int fstatat(int fildes, const char *path, struct stat *buf, int flag);
DESCRIPTION The stat() function obtains information about the file pointed to by path. Read, write, or execute permission of the named file is not required, but all directories listed in the path name leading to the file must be searchable.
So, could anybody either show me how to get "stat" on Solaris? Or how to use the "stat()" function in a "C" program on Solaris?
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
The GNU command stat is bundled with OpenSolaris and Solaris 11 and available on the Solaris companion CD with Solaris 10. However, GNU stat isn't fully aware of Solaris file system capabilities so I would suggest to use ls instead to get file information.
For example on Solaris 11 stat is unable to display the file creation time while ls does it well when given the proper options. stat doesn't either show ACLs.
Code:
$ ls -l z
-rw-rw-rw-+ 1 jlliagre staff 29 Mar 14 22:48 z
$ stat z
File: `z'
Size: 29 Blocks: 2 IO Block: 512 regular file
Device: 1a50008h/27590664d Inode: 125613 Links: 1
Access: (0666/-rw-rw-rw-) Uid: ( 101/jlliagre) Gid: ( 10/ staff)
Access: 2012-03-14 22:49:15.242808311 +0100
Modify: 2012-03-14 22:48:36.115123337 +0100
Change: 2012-03-14 22:52:11.751512260 +0100
$ ls -siv -@ -/ c -%all z
125613 2 -rw-rw-rw-+ 1 jlliagre staff 29 Mar 14 22:48 z
{A------m--}
timestamp: atime Mar 14 22:49:15 2012
timestamp: ctime Mar 14 22:52:11 2012
timestamp: mtime Mar 14 22:48:36 2012
timestamp: crtime Dec 19 09:56:17 2011
0:user:daemon:read_data:deny
1:owner@:read_data/write_data/append_data/read_xattr/write_xattr
/read_attributes/write_attributes/read_acl/write_acl/write_owner
/synchronize:allow
2:group@:read_data/write_data/append_data/read_xattr/read_attributes
/read_acl/synchronize:allow
3:everyone@:read_data/write_data/append_data/read_xattr/read_attributes
/read_acl/synchronize:allow
The options "-/" and "-%" (all) do not work with "ls". I checked it on CentOS 6.0 and Solaris 10:
PHP Code:
bash-3.2# uname -a SunOS dev-host 5.10 Generic_147441-01 i86pc i386 i86pc
bash-3.2# cat /etc/release Oracle Solaris 10 8/11 s10x_u10wos_17b X86 Copyright (c) 1983, 2011, Oracle and/or its affiliates. All rights reserved. Assembled 23 August 2011 bash-3.2#
The other options work and make sense on Solaris but not on Linux as Linux complains about "-@" also:
Code:
bash-3.2# ls -siv -@ -c z
297581 0 -rw-r--r-- 1 root root 0 Mar 17 02:53 z
0:user::rw-
1:group::r-- #effective:r--
2:mask:r--
3:other:r--
bash-3.2#
Code:
[demo@localhost ~]$ ls -siv -c z
65721 1 z
[demo@localhost ~]$
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
My example was, as I wrote, on Solaris 11. There is no much point trying to use the options presented with Centos which is not Solaris and which uses GNU ls, not Solaris ls. Some of the options are not implemented either on Solaris 10 as you noticed.
I'm unclear about what you are trying to achieve. If you want to see what the stat library function do, here is a way:
Code:
$ truss -t lstat64 -v lstat64 ls z
lstat64("z", 0x08046120) = 0
d=0x01A50002 i=329844 m=0100644 l=1 u=101 g=10 sz=0
at = Mar 16 22:31:34 CET 2012 [ 1331933494.369354656 ]
mt = Mar 16 22:23:04 CET 2012 [ 1331932984.529923081 ]
ct = Mar 16 23:00:52 CET 2012 [ 1331935252.974425479 ]
bsz=512 blks=1 fs=zfs
z
This should work on both Solaris 10 and 11.
Here is something similar that should work on Centos:
Code:
$ strace -v -e trace=stat ls z
stat("z", {st_dev=makedev(8, 8), st_ino=665469, st_mode=S_IFREG|0644, st_nlink=1,
st_uid=1000, st_gid=1000, st_blksize=4096, st_blocks=0, st_size=0,
st_atime=2012/03/17-00:05:50, st_mtime=2012/03/17-00:05:50,
st_ctime=2012/03/17-00:05:50}) = 0
z
You had already got it and provided the insight on the problem by introducing the interesting options to the "ls" command. I just wondered if the "ls" command on CentOS 6 or Solaris 10 had similar options.
The last one that you have given above is not working on my CentOS 6:
Code:
[demo@localhost ~]$ strace -v -e trace=stat ls z
z
[demo@localhost ~]$
By the way, thanks again for your time and effort! You're appreciated!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.