查看文件状态 stat

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

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

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

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

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

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

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

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

    how to create a ring progress bar in web skills ring progress bar & circle progress bar canvas j ...

  2. CSS3 & CSS var & :root

    CSS3 & CSS var & :root How to change CSS :root color variables in JavaScript https://stackov ...

  3. GitHub Actions

    GitHub Actions CI/CD & testing https://github.com/features/actions refs xgqfrms 2012-2020 www.cn ...

  4. html5 useful skills blogs

    html5 useful skills blogs preload & prefetch https://www.30secondsofcode.org/snippet/ary blogs h ...

  5. 1107 Social Clusters——PAT甲级真题

    1107 Social Clusters When register on a social network, you are always asked to specify your hobbies ...

  6. 如何创建一个Maven项目(eclipse版本)

    1 Maven概念 Maven是一个构建项目和管理项目依赖的工具 2 Maven运行原理 这里需要引入两个词汇,叫 本地仓库.中央仓库 本地仓库:就字面意思,存储在自己电脑上的文件夹(需要自己手动创建 ...

  7. VMware 安装 CentOS7 后的简单配置

    1.连网 如果能连网,跳过此步 试着ping一下百度 ping baidu.com 动态分配 IP sudo vim /etc/sysconfig/network-scripts/ifcfg-ens3 ...

  8. 使用dlopen加载动态库

    目录 概述 接口 C CMakeLists.txt src/main.c src/add.c ./dlopen_test C++ CMakeLists.txt src/main.cpp src/add ...

  9. vivo 官网资源包适配多场景的应用

    本文介绍了资源包的概念及使用场景,同时对资源包的几种使用方案进行对比.通过本文,大家可以快速掌握资源包的使用方法,解决单一配置满足多场景.多样式的问题. 一.业务背景 随着官网项目的业务深入发展,单纯 ...

  10. three.js cannon.js物理引擎之约束(二)

    今天郭先生继续讲cannon.js的物理约束,之前的一篇文章曾简单的提及过PointToPointConstraint约束,那么今天详细的说一说cannon.js的约束和使用方法.在线案例请点击博客原 ...