LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This 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


Reply
  Search this Thread
Old 03-14-2012, 12:25 PM   #1
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Rep: Reputation: 59
stat command on Solaris


Gurus!


(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?

On "forums.oracle.com", there is a similar discussion but it does not help me much.


I just got this piece of information on Solaris by executing the man command:

Code:
man 8 stat
and here is an excert from it:

PHP Code:

System Calls                                              stat
(2)

NAME
     stat
lstatfstatfstatat get file status

SYNOPSIS
     
#include <fcntl.h>
     #include <sys/types.h>
     #include <sys/stat.h>

     
int stat(const char *restrict pathstruct stat *restrict buf);

     
int lstat(const char *restrict pathstruct stat *restrict buf);

     
int fstat(int fildesstruct stat *buf);

     
int fstatat(int fildes, const char *pathstruct stat *buf,
         
int flag);

DESCRIPTION
     The stat
()  function  obtains  information  about  the  file
     pointed  to  by  path
Readwrite, 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?

Last edited by devUnix; 03-14-2012 at 01:18 PM.
 
Old 03-14-2012, 05:58 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
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
 
1 members found this post helpful.
Old 03-16-2012, 04:31 PM   #3
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
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 
(c19832011Oracle and/or its affiliatesAll 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 ~]$
 
Old 03-16-2012, 06:04 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
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

Last edited by jlliagre; 03-16-2012 at 06:11 PM.
 
1 members found this post helpful.
Old 03-17-2012, 02:28 PM   #5
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by jlliagre View Post
I'm unclear about what you are trying to achieve.
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!

Last edited by devUnix; 03-17-2012 at 02:30 PM.
 
Old 03-17-2012, 03:48 PM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by devUnix View Post
The last one that you have given above is not working on my CentOS 6:
Okay, try that slightly modified one:
Code:
strace -v -e trace=lstat ls z
 
Old 03-17-2012, 05:23 PM   #7
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by jlliagre View Post
Okay, try that slightly modified one:
Code:
strace -v -e trace=lstat ls z
Same output:

Code:
[demo@localhost ~]$ strace -v -e trace=lstat ls z
z
But at least you showed how to use them. Thanks!
 
Old 03-18-2012, 05:14 AM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Double check. The first command I suggested works fine here with Centos 6:

Code:
[demo@localhost ~]$ cat /etc/redhat-release
CentOS release 6.2 (Final)
[demo@localhost ~]$ stat z
  File: `z'
  Size: 29          Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d  Inode: 16983       Links: 1
Access: (0660/-rw-rw----)  Uid: (  500/    demo)   Gid: (  500/    demo)
Access: 2012-03-18 11:06:28.394729259 +0100
Modify: 2012-03-18 11:06:31.563148813 +0100
Change: 2012-03-18 11:06:38.217166359 +0100
[demo@localhost ~]$ strace -v -e trace=stat ls z
stat("z", {st_dev=makedev(253, 0), st_ino=16983, st_mode=S_IFREG|0660,
st_nlink=1, st_uid=500, st_gid=500, st_blksize=4096, st_blocks=8,
st_size=29, st_atime=2012/03/18-11:06:28, st_mtime=2012/03/18-11:06:31, st_ctime=2012/03/18-11:06:38}) = 0
z
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
date formatting from stat command tensigh Programming 10 08-30-2010 04:13 AM
stat command ravidangaych Linux - General 3 09-22-2009 05:02 AM
[SOLVED] gcc linker error - hidden symbol `stat' in /usr/lib/libc_nonshared.a(stat.oS) chaosless Linux - Software 1 09-17-2009 12:33 PM
stat command joshnya Linux - Newbie 3 05-30-2008 04:58 AM
Stat command output description jackloo Linux - Newbie 2 09-28-2007 08:31 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 12:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration