本文最后更新于 257 天前,其中的信息可能已经过时,如有错误请发送邮件到wuxianglongblog@163.com
stat命令查看文件状态(三个时间戳)
三个时间戳:
access time:访问时间,atime,读取文件内容
modify time: 修改时间, mtime,改变文件内容(数据)
change time: 改变时间, ctime,元数据发生改变
选项
-L:支持符号连接;
-f:显示文件系统状态而非文件状态;
-t:以简洁方式输出信息;
--help:显示指令的帮助信息;
--version:显示指令的版本信息
事实上,stat命令显示的是文件的I节点信息。Linux文件系统以块为单位存储信息,为了找到某一个文件所在存储空间的位置,用Inode节点对每个文件进行索引。
所谓的Inode节点,是文件系统管理的一个数据结构,是一个64字节长的表,包含了描述文件所必要的全部信息,其中包含了文件的大小,类型,存取权限,文件的所有者等
举例:
查询rc.d文件的信息
[root@redhat rc.d]# stat rc0.d/ //可以清楚的分析文件或目录的信息
File: `rc0.d/'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: fd00h/64768d Inode: 1309217 Links: 2
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-06-26 21:02:26.776082938 +0800
Modify: 2014-06-12 15:16:57.848087079 +0800
Change: 2014-06-12 15:16:57.848087079 +0800
[root@redhat rc0.d]# du -sh //这个目录下的所有文件共4K和上面大小差不多
4.0K .
查询ec.d文件所在文件系统的信息:
[root@redhat rc.d]# stat -f rc0.d/ //这个显示的跟当前系统的文件系统信息一样,因为rc.0就在当前系统的文件系统
File: "rc0.d/"
ID: 303116b72802c784 Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 7558388 Free: 5545748 Available: 5161800
Inodes: Total: 1921360 Free: 1850717
也可以查看硬盘的信息
[root@redhat rc.d]# stat /dev/sda
File: `/dev/sda'
Size: 0 Blocks: 0 IO Block: 4096 block special file
Device: 5h/5d Inode: 6308 Links: 1 Device type: 8,0
Access: (0660/brw-rw----) Uid: ( 0/ root) Gid: ( 6/ disk)
Access: 2014-06-27 20:57:07.213940088 +0800
Modify: 2014-06-27 20:57:05.037938949 +0800
Change: 2014-06-27 20:57:05.037938949 +0800
sda硬盘文件系统的信息
[root@redhat rc.d]# stat -f /dev/sda
File: "/dev/sda"
ID: 0 Namelen: 255 Type: tmpfs
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 61793 Free: 61734 Available: 61734
Inodes: Total: 61793 Free: 61080
-L,跟踪显示链接文件信息
yexiang@ubuntu:<~>$ ls -al link_vim
lrwxrwxrwx 1 yexiang yexiang 20 Jul 11 23:02 link_vim -> /home/yexiang/yxvim_
yexiang@ubuntu:<~>$ stat -L link_vim
File: 'link_vim'
Size: 14601 Blocks: 32 IO Block: 4096 regular file
Device: 806h/2054d Inode: 1591023 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ yexiang) Gid: ( 1000/ yexiang)
Access: 2018-07-03 02:23:59.909422577 -0700
Modify: 2018-07-03 02:23:41.772933205 -0700
Change: 2018-07-03 02:23:46.657064991 -0700
Birth: -
yexiang@ubuntu:<~>$ stat link_vim
File: 'link_vim' -> '/home/yexiang/yxvim_'
Size: 20 Blocks: 0 IO Block: 4096 symbolic link
Device: 806h/2054d Inode: 1591059 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 1000/ yexiang) Gid: ( 1000/ yexiang)
Access: 2018-07-11 23:02:55.359010673 -0700
Modify: 2018-07-11 23:02:54.239011896 -0700
Change: 2018-07-11 23:02:54.239011896 -0700
Birth: -
[root@localhost ~]# stat anaconda-ks.cfg
File: ‘anaconda-ks.cfg’
Size: 1803 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 25165890 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:admin_home_t:s0
Access: 2024-01-09 22:35:30.455606958 +0800
Modify: 2024-01-09 19:29:38.529573856 +0800
Change: 2024-01-09 19:29:38.529573856 +0800
Birth: -
[root@localhost ~]# touch anaconda-ks.cfg //touch更新三个时间
[root@localhost ~]# stat anaconda-ks.cfg
File: ‘anaconda-ks.cfg’
Size: 1803 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 25165890 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:admin_home_t:s0
Access: 2024-01-09 22:53:07.973542205 +0800
Modify: 2024-01-09 22:53:07.973542205 +0800
Change: 2024-01-09 22:53:07.973542205 +0800
Birth: -
[root@localhost ~]#
[root@localhost ~]# touch -t 202001010101 anaconda-ks.cfg //加-t指定atime和mtime
[root@localhost ~]# stat anaconda-ks.cfg
File: ‘anaconda-ks.cfg’
Size: 1803 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 25165890 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:admin_home_t:s0
Access: 2020-01-01 01:01:00.000000000 +0800
Modify: 2020-01-01 01:01:00.000000000 +0800
Change: 2024-01-09 22:54:46.678536161 +0800
Birth: -
[root@localhost ~]#