查看文件状态 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. super fast sort algorithm in js

    super fast sort algorithm in js sort algorithm Promise.race (return the fast one) Async / Await // c ...

  2. React & Strict Mode

    React & Strict Mode https://reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects ...

  3. auto responsive rem

    auto responsive rem 移动端适配 ;(function(win, lib) { var doc = win.document; var docEl = doc.documentEle ...

  4. Bootstrap5 多级dropdown

    <div class="dropdown"> <a class="btn dropdown-toggle"> Dropdown link ...

  5. NGK算力持有好处多多!SPC、VAST等免费拿!

    众所周知,NGK是分布式存储的,作为Web3.0以及数字经济时代的基础设施,为数字加密市场带来了全新的商业模式和经济业态,但是,这只是一个重要的起点,真正的价值还在后面! 为了满足NGK生态建设者强烈 ...

  6. Baccarat流动性挖矿的收益能否持续?该如何参与Baccarat流动性挖矿?

    2020年DeFi市场火热,众多投资机构纷纷入场,分享这场资本盛宴.然而,目前市面上大多数DeFi项目手续费高昂,小资金的投资者无法入市.为了让更多的用户参与其中,NGK推出了Baccarat流动性挖 ...

  7. Basic认证时添加请求头

    http Basic认证 http协议定义的一种认证方式,将客户端id和客户端密码按照"客户端ID:客户端密码"的格式拼接,并用base64编 码,放在header中请求服务端, ...

  8. Ctf_show Web[1-8]

    CTFshow_web1: F12查看JS即在代码里 CTFshow_web2: 进入网址后页面如下: ①:尝试使用admin登陆,发现页面无回显 ②:尝试单引号闭合,并且添加' or 1=1#,此时 ...

  9. Vue框架-组件的概念及使用

    目录 一.Vue组件 1. 组件分类 1.1 根组件 1.2 局部组件 1.3 全局组件 2. 组件的特点 3. 如何创建组件 4. 组件的数据局部化 5. 组件传参·父传子 6. 组件传参·子传父 ...

  10. Centos7 升级 sqlite3

    下载地址:https://www.sqlite.org/download.html [root@djangoServer ~]# wget https://www.sqlite.org/2019/sq ...