查看文件状态 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. JavaScript Number Type Checker

    JavaScript Number Type Checker Number.isInteger // static 方法 Number.isInteger(value) https://develop ...

  2. CSS Dark Mode

    CSS Dark Mode https://kevq.uk/automatic-dark-mode/ https://kevq.uk/how-to-add-css-dark-mode-to-a-web ...

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

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

  4. C++ 中的智能指针-基础

    简介 在现代 C++ 编程中,标准库包含了智能指针(Smart pointers). 智能指针用来确保程序不会出现内存和资源的泄漏,并且是"异常安全"(exception-safe ...

  5. [转]LINUX下编译c++11的代码

    转载地址: https://blog.csdn.net/lwb102063/article/details/50445201 C++11,(即ISO/IEC 14882:2011),是目前的C++编程 ...

  6. 【HTB系列】靶机Access的渗透测试详解

    出品|MS08067实验室(www.ms08067.com) 本文作者:大方子(Ms08067实验室核心成员) Hack The Box是一个CTF挑战靶机平台,在线渗透测试平台.它能帮助你提升渗透测 ...

  7. JDK源码阅读-Reference

    本文转载自JDK源码阅读-Reference 导语 Java最初只有普通的强引用,只有对象存在引用,则对象就不会被回收,即使内存不足,也是如此,JVM会爆出OOME,也不会去回收存在引用的对象. 如果 ...

  8. java: 类 RegisterController 是公共的, 应在名为 RegisterController.java 的文

    public声明的类名需要和文件名一致,检查一下

  9. where & having 关键字

    where和having都是做条件筛选的 where执行的时间比having要早 where后面不能出现组函数 having后面可以出现组函数 where语句要跟在from后面 ,where 不能单独 ...

  10. idea没有错误提示的解决方法(一直处于错误分析中)

    仅作记录,以防再次发生却不记得. 原文链接:https://blog.csdn.net/a755199443/article/details/90084316 问题描述:idea没有自动报错.例如随便 ...