Mac OS X 10.6 /usr/bin/stat 命令,显示我的默认输出是什么?

use*_*688 7 unix stat macos

当我运行 stat 命令时,实际显示的输出是什么?我知道您可以指定格式,但我正在对从 OS X 到 NetApp SMB 的 rsync 进行故障排除,并试图找出复制和不复制的内容。

# stat /Volumes/Media/MediaBank/WEB_D/41/zoomify/41999V21.jpg
234881039 281475121196473 -rwxr--r-- 1 mbank wheel 0 378716 "Aug  9 19:17:50 2010" "Jan  3 12:56:26 2010" "Apr 26 09:34:13 2010" "Dec 27 23:35:32 2009" 16384 768 0 /Volumes/Media/MediaBank/WEB_D/41/zoomify/41999V21.jpg
Run Code Online (Sandbox Code Playgroud)

这是同步到 SAN 的副本。

# stat /Volumes/SAN_Media/MediaBank1/WEB_D/41/zoomify/41999V21.jpg
771751969 10654547399 -rwx------ 1 root wheel 0 378716 "Aug  9 09:39:45 2010" "Jan  3 12:56:26 2010" "Jul 23 17:52:30 2010" "Jan  3 12:56:26 2010" 33028 744 0 /Volumes/SAN_Media/MediaBank1/WEB_D/41/zoomify/41999V21.jpg
Run Code Online (Sandbox Code Playgroud)

我对输出格式的猜测是这样的..

unknown1 unknown2 permissions unknown3 uid gid linkcount bytes time1 time2 time3 time4 unknown4 unknown5 unknown6 fullpath .. 
Run Code Online (Sandbox Code Playgroud)

至于时间,我猜他们中的三个必须是atime,mtime和ctime,但是为什么有第4个,哪个是哪个?

Jan*_*nen 11

我不是 OS X 用户,但我熟悉 FreeBSD。带有它的 stat 输出看起来和你的一样,但是如果你想澄清一些东西是人类可读的,使用stat -x your_path.

哦,那些字段是什么?也许OS X 文档中的这个片段有帮助:

struct stat { /* when _DARWIN_FEATURE_64_BIT_INODE is NOT defined */
     dev_t    st_dev;    /* device inode resides on */
     ino_t    st_ino;    /* inode's number */
     mode_t   st_mode;   /* inode protection mode */
     nlink_t  st_nlink;  /* number or hard links to the file */
     uid_t    st_uid;    /* user-id of owner */
     gid_t    st_gid;    /* group-id of owner */
     dev_t    st_rdev;   /* device type, for special file inode */
     struct timespec st_atimespec;  /* time of last access */
     struct timespec st_mtimespec;  /* time of last data modification */
     struct timespec st_ctimespec;  /* time of last file status change */
     off_t    st_size;   /* file size, in bytes */
     quad_t   st_blocks; /* blocks allocated for file */
     u_long   st_blksize;/* optimal file sys I/O ops blocksize */
     u_long   st_flags;  /* user defined flags for file */
     u_long   st_gen;    /* file generation number */
 };
Run Code Online (Sandbox Code Playgroud)


小智 6

梳理 Janne 和 Gordon 的回答:

stat无标志调用:

$ stat Report.docx 
234881026 23858800 -rw-r--r-- 1 will staff 0 176083 "Apr 29 11:44:25 2012" "Apr 29 11:14:56 2012" "Apr 29 11:14:56 2012" "Apr 27 19:22:39 2012" 4096 344 0 Report.docx
Run Code Online (Sandbox Code Playgroud)

Callingstat -x给出了人类可读的标签,但只定义了 4 个日期中的 3 个:

$ stat -x Report.docx 
  File: "Report.docx"
  Size: 176083       FileType: Regular File
  Mode: (0644/-rw-r--r--)         Uid: (  501/    will)  Gid: (   20/   staff)
Device: 14,2   Inode: 23858800    Links: 1
Access: Sun Apr 29 11:44:25 2012
Modify: Sun Apr 29 11:14:56 2012
Change: Sun Apr 29 11:14:56 2012
Run Code Online (Sandbox Code Playgroud)

打电话stat -s给我们一个更好的答案:

$ stat -s Report.docx 
st_dev=234881026 st_ino=23858800 st_mode=0100644 st_nlink=1 st_uid=501 st_gid=20 st_rdev=0 st_size=176083 st_atime=1335663865 st_mtime=1335662096 st_ctime=1335662096 st_birthtime=1335518559 st_blksize=4096 st_blocks=344 st_flags=0
Run Code Online (Sandbox Code Playgroud)

在这里我们看到四个日期:st_atime, st_mtime, st_ctime, st_birthtime

st_birthtime详细 ( -x) 输出中缺少- 对我来说,这与createdFinder 显示的日期相匹配。


查看手册页,第二个记录的 struct ( when _DARWIN_FEATURE_64_BIT_INODE is defined) 显示了四个日期,并在下面定义了它们。

 The time-related fields of struct stat are as follows:

 st_atime         Time when file data last accessed.  Changed by the mknod(2), utimes(2) and read(2)
                  system calls.

 st_mtime         Time when file data last modified.  Changed by the mknod(2), utimes(2) and write(2)
                  system calls.

 st_ctime         Time when file status was last changed (inode data modification).  Changed by the
                  chmod(2), chown(2), link(2), mknod(2), rename(2), unlink(2), utimes(2) and write(2)
                  system calls.

 st_birthtime     Time of file creation. Only set once when the file is created. This field is only
                  available in the 64 bit inode variants. On filesystems where birthtime is not avail-
                  able, this field holds the ctime instead.
Run Code Online (Sandbox Code Playgroud)

因此,根据您的架构,第四个日期是创建日期(64 位时)或重复的 ctime