查看文件状态 stat

ls 命令能够查看文件的类型、时间、属主、属组,大小以及最近的修改时间等信息,但是还有一些文件的扩展属性,是使用 ls 命令无法查看到的

stat 命令则用于显示文件的详细属性

面试题:linux操作系统中,一个文件的MAC time代表什么意思,如何查看一个文件的MAC time?

  • access time:表示我们最后一次访问(仅仅是访问,没有改动)文件的时间

  • modify time:表示我们最后一次修改文件的时间

  • change time:表示我们最后一次对文件属性改变的时间,包括权限,大小,属性等等。

Linux文档的时间一般分三种:

  • Access time(访问时间),atime 可以通过 ls -lu 命令显示,表示文档最后被访问的时间。
[root@centos /tmp]#ll a.log                    # 原文件是 24 号的
-rw-r--r--. 1 root root 0 Mar 24 18:59 a.log
[root@centos /tmp]#cat a.log # cat 之后 atime 会改变
[root@centos /tmp]#stat a.log # 通过 stat 命令查看
File: a.log
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 805h/2053d Inode: 1866 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2021-03-26 10:13:04.011131156 +0800 # 查看之后会改变为当前时间 26 号,一天之内的访问不会多次改变
Modify: 2021-03-24 18:59:46.273586607 +0800 # 没有改变,还是 24 号
Change: 2021-03-24 18:59:46.273586607 +0800 # 没有改变,还是 24 号
Birth: -
[root@centos /tmp]#
  • Modification time(内容修改时间), mtime 可以通过 ls -l 命令显示,表示文档内容最后被修改的时间。
[root@centos /tmp]#ll d.log                 # 原文件是 24 号的
-rw-r--r--. 1 root root 0 Mar 24 18:59 d.log
[root@centos /tmp]#stat d.log
File: d.log
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 805h/2053d Inode: 293401 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2021-03-24 18:59:46.273586607 +0800
Modify: 2021-03-24 18:59:46.273586607 +0800
Change: 2021-03-24 18:59:46.273586607 +0800
Birth: -
[root@centos /tmp]#vim d.log # 编辑文件
[root@centos /tmp]#stat d.log
File: d.log
Size: 12 Blocks: 8 IO Block: 4096 regular file
Device: 805h/2053d Inode: 293401 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2021-03-26 10:29:31.829155649 +0800 # 改变为当前时间 26 号
Modify: 2021-03-26 10:29:36.934155776 +0800 # 改变为当前时间 26 号
Change: 2021-03-26 10:29:36.936155776 +0800 # 改变为当前时间 26 号
Birth: -
[root@centos /tmp]#
  • change time(改变时间),ctime 可以通过 ls -lc 命令显示,表示文档属性最后被修改的时间
[root@centos /tmp]#ll c.log                   # 原文件是 24 号的
-rw-r--r--. 1 root root 0 Mar 24 18:59 c.log
[root@centos /tmp]#stat c.log
File: c.log
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 805h/2053d Inode: 293397 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2021-03-24 18:59:46.273586607 +0800
Modify: 2021-03-24 18:59:46.273586607 +0800
Change: 2021-03-24 18:59:46.273586607 +0800
Birth: -
[root@centos /tmp]#chown song.root c.log # 改变文件的属主
[root@centos /tmp]#ll c.log # 确认属主已改为 song 所有
-rw-r--r--. 1 song root 0 Mar 24 18:59 c.log
[root@centos /tmp]#stat c.log
File: c.log
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 805h/2053d Inode: 293397 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ song) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2021-03-24 18:59:46.273586607 +0800 # 没有改变,还是 24 号
Modify: 2021-03-24 18:59:46.273586607 +0800 # 没有改变,还是 24 号
Change: 2021-03-26 10:23:22.390146489 +0800 # 改变为当前时间 26 号了
Birth: -
[root@centos /tmp]#

总结

  • 当我们仅仅只是读取文件时,access time 改变,而modify,change time 不会改变

  • 当修改文件时,access,modify,change time 都会跟着改变

  • 当修改文件属性时,change time 改变,而access,modify time 不变。

面试题:Linux 中一个文件的 MAC 代表什么意思的更多相关文章

  1. Linux中一个文件10行内容,如何输出5-8内容到屏幕

    题目是这样的,Linux中一个文件10行内容,如何输出5-8内容到屏幕首先我们模拟一下这样的环境: [root@localhost question]# pwd /root/question [roo ...

  2. Linux中检索文件

    1 , Use locate command It is a fast way to find the files location, but if a file just created ,it w ...

  3. 在Linux中查看文件的编码及对文件进行编码转换

    如果你需要在Linux中操作windows下的文件,那么你可能会经常遇到文件编码转换的问题.Windows中默认的文件格式是GBK(gb2312),而Linux一般都是UTF-8.下面介绍一下,在Li ...

  4. Linux中的文件描述符与打开文件之间的关系

    Linux中的文件描述符与打开文件之间的关系 导读 内核(kernel)利用文件描述符(file descriptor)来访问文件.文件描述符是非负整数.打开现存文件或新建文件时,内核会返回一个文件描 ...

  5. 5 个在 Linux 中管理文件类型和系统时间的有用命令

    对于想学习 Linux 的初学者来说要适应使用命令行或者终端可能非常困难.由于终端比图形用户界面程序更能帮助用户控制 Linux 系统,我们必须习惯在终端中运行命令.因此为了有效记忆 Linux 不同 ...

  6. linux中的文件编码及编码修改

    查看文件编码 在Linux中查看文件编码可以通过以下几种方式: 1.在Vim中可以直接查看文件编码 :set fileencoding 即可显示文件编码格式. 如果你只是想查看其它编码格式的文件或者想 ...

  7. 工具WinSCP:windows和Linux中进行文件传输

    工具WinSCP:windows和Linux中进行文件传输 2016-09-21 [转自]使用WinSCP软件在windows和Linux中进行文件传输 当我们的开发机是Windows,服务器是Lin ...

  8. 【转】linux中inittab文件详解

    原文网址:http://www.2cto.com/os/201108/98426.html linux中inittab文件详解 init的进程号是1(ps -aux | less),从这一点就能看出, ...

  9. linux中删除文件内空白行的几种方法。

    linux中删除文件内空白行的几种方法 有时你可能需要在 Linux 中删除某个文件中的空行.如果是的,你可以使用下面方法中的其中一个.有很多方法可以做到,但我在这里只是列举一些简单的方法. 你可能已 ...

随机推荐

  1. react fiber

    react fiber https://github.com/acdlite/react-fiber-architecture https://github.com/facebook/react/is ...

  2. c++ 设置桌面壁纸(win)

    #include <iostream> #include <Windows.h> int main() { const char* path = "C:\\Users ...

  3. css-next & grid layout

    css-next & grid layout css3 demo https://alligator.io/ @media only screen and (max-width: 30em) ...

  4. html fragment & html template & virtual DOM & web components

    html fragment & html template & virtual DOM https://developer.mozilla.org/en-US/docs/Web/API ...

  5. js 触发长按事件

    为网站添加触摸功能 <button id="btn1">长按触发</button> <button id="btn2">长按 ...

  6. Django Admin 删除文件同时删除资源文件(delete_upload_files)

    一  使用环境 开发系统: windows IDE: pycharm 数据库: msyql,navicat 编程语言: python3.7  (Windows x86-64 executable in ...

  7. 为什么ConcurrentHashMap,HashTable不支持key,value为null?

    ConcurrentHashmap.HashMap和Hashtable都是key-value存储结构,但他们有一个不同点是 ConcurrentHashmap.Hashtable不支持key或者val ...

  8. 更换 grub 主题

    默认的 grub 界面比较简陋 然后突然有想法了,想换个主题 具体操作 1.下载 grub 主题包 去这个地址下载主题(应该是这个地址): https://www.gnome-look.org/bro ...

  9. Git:版本库建立与状态查看

    版本库又名仓库,英文名repository,可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改.删除,Git都能跟踪,以便任何时刻都可以追踪历史,或者在将来某个时刻可 ...

  10. 基于Hi3559AV100的SVP(NNIE)开发整体流程

    在之后的hi3559AV100板载开发中,除了走通V4L2->VDEC->VPSS->VO(HDMI)输出,还有需要进行神经网络的开发学习,进行如face detection的开发等 ...