Linux命令-stat

一、简述:

        在Linux中,没有文件创建时间的概念。只有文件的访问时间、修改时间、状态改变时间。也就是说不能知道文件的创建时间。但如果文件创建后就没有修改过,修改时间=创建时间;如果文件创建后,状态就没有改变过,那么状态改变时间=创建时间;如果文件创建后,没有被读取过,那么访问时间=创建时间,这个基本不太可能。

与文件相关的几个时间:
1、访问时间: 读一次这个文件的内容,这个时间就会更新。比如对这个文件使用more,cat等;
2、修改时间: 对文件内容修改一次,这个时间就会更新。比如:vi后保存文件。ls -l列出的时间就是这个时间;
3、状态改变时间: 通过chmod,chown等命令更改一次文件属性,这个时间就会更新。查看文件的详细的状态、准确的修改时间等。

二、命令的格式及语法详解:

1、命令格式:
NAME
stat – display file or file system status(显示文件或文件系统的状态信息)

SYNOPSIS
stat [OPTION]… FILE…

2、参数详解:

-L, –dereference
根据链接文件的指向,显示物理文件的状态信息,如果有多重链接信息,则会最终显示最后实际文件的信息;
-Z, –context
打印SELinux的安全上下文
-f, –file-system
显示文件系统的状态,而不是文件状态
-c –format=FORMAT
使用指定的格式来取代是默认格式;每次使用FORMAT后输出一个换行符
–printf=FORMAT
作用类似于–format,但解释反斜杠,并且不输出强制性尾随的换行符。如果你想要换行,需要在FORMAT中包含\n。
-t, –terse
打印简洁形式的信息

三、实例演示:

1、取消链接,显示物理文件的信息:

shell> ls -l a.l* 
lrwxrwxrwx  1 root   root       5 May 20 22:24 a.link -> a.log
lrwxrwxrwx  1 root   root       6 May 20 22:34 a.link2 -> a.link
-rwxr-xr-x. 1 nobody root 2956842 May 20 22:16 a.log

shell> stat a.log 
  File: `a.log'
  Size: 2956842   	Blocks: 5776       IO Block: 4096   regular file
Device: fd00h/64768d	Inode: 675203      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (   99/  nobody)   Gid: (    0/    root)
Access: 2016-05-20 22:15:56.492030888 +0800
Modify: 2016-05-20 22:16:17.759391891 +0800
Change: 2016-05-20 22:17:16.520699890 +0800

shell> stat a.link
  File: `a.link' -> `a.log'
  Size: 5         	Blocks: 0          IO Block: 4096   symbolic link
Device: fd00h/64768d	Inode: 677971      Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-05-20 22:24:43.891699890 +0800
Modify: 2016-05-20 22:24:42.812699890 +0800
Change: 2016-05-20 22:24:42.812699890 +0800

shell> stat a.link2 
  File: `a.link2' -> `a.link'
  Size: 6         	Blocks: 0          IO Block: 4096   symbolic link
Device: fd00h/64768d	Inode: 677975      Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-05-20 22:35:01.152793576 +0800
Modify: 2016-05-20 22:34:58.239793576 +0800
Change: 2016-05-20 22:34:58.239793576 +0800

shell> stat -L a.link2 
  File: `a.link2'
  Size: 2956842   	Blocks: 5776       IO Block: 4096   regular file
Device: fd00h/64768d	Inode: 675203      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (   99/  nobody)   Gid: (    0/    root)
Access: 2016-05-20 22:15:56.492030888 +0800
Modify: 2016-05-20 22:16:17.759391891 +0800
Change: 2016-05-20 22:17:16.520699890 +0800

shell> stat -L a.link
  File: `a.link'
  Size: 2956842   	Blocks: 5776       IO Block: 4096   regular file
Device: fd00h/64768d	Inode: 675203      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (   99/  nobody)   Gid: (    0/    root)
Access: 2016-05-20 22:15:56.492030888 +0800
Modify: 2016-05-20 22:16:17.759391891 +0800
Change: 2016-05-20 22:17:16.520699890 +0800

2、显示文件系统的状态:

shell> stat -f a.log 
  File: "a.log"
    ID: 962c66c39d2643f8 Namelen: 255     Type: ext2/ext3
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 102581292  Free: 69288925   Available: 64083574
Inodes: Total: 25956960   Free: 25435821

3、常用的format的使用:

%g Group ID of owner
文件所有者的group ID
%G Group name of owner
文件所有者的group name
%i Inode number
inode 编号
%o I/O block size
文件对应的block的大小
%s Total size, in bytes
文件的大小,单位:byte
%u User ID of owner
文件所有者的用户ID
%U User name of owner
文件所有者的用户名
%x Time of last access
该文件最近一次的访问时间
%X Time of last access as seconds since Epoch
以时间戳的形式显示文件最近一次的访问时间
%y Time of last modification
文件最近一次修改的时间
%Y Time of last modification as seconds since Epoch
以时间戳的形式显示文件最近一次修改的时间
%z Time of last change
文件最近一次状态改变的时间
%Z Time of last change as seconds since Epoch
以时间错的形式显示文件最近一次状态改变的时间

暂无评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注

Time limit is exhausted. Please reload CAPTCHA.