Linux系统ctime、mtime和atime命令详解linux操作系统 电脑资料_第1页
Linux系统ctime、mtime和atime命令详解linux操作系统 电脑资料_第2页
Linux系统ctime、mtime和atime命令详解linux操作系统 电脑资料_第3页
Linux系统ctime、mtime和atime命令详解linux操作系统 电脑资料_第4页
Linux系统ctime、mtime和atime命令详解linux操作系统 电脑资料_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Linux系统ctime、mtime和atime命令详解linux操作系统 电脑资料 在linux中对于文件有ctime、mtime和atime三种时间,一种是访问时间,一种是修改时间,另一种是改变文件时间了,下面一起来看看吧, atime:Aess Time 最后一次访问文件(读取或执行)或目录的时间 mtime:Modofy Time 最后一次修改文件(内容)或目录(内容)的时间 ctime:Change Time 最后一次改变文件(属性)或目录(属性)的时间 如何查看文件或目录的atime/mtime/ctime 1、stat filename 2、 atime: ls -lu filename mtime: ls -l filename ctime: ls -lc filename 示例演示 在/tmp下新建一个目录tm,tm下新建一个文件a.txt # mkdir tm # cd tm # stat ./tm File: ./tm Size: 4096 Blocks: 8 IO Block: 4096 directory Device: ca01h/51713d Inode: 1050207 Links: 2 Aess: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Aess: xx-03-17 10:57:32.993350411 +0800 Modify: xx-03-17 10:57:32.993350411 +0800 Change: xx-03-17 10:57:32.993350411 +0800 Birth: - # touch a.txt # stat a.txt File: a.txt Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: ca01h/51713d Inode: 1050208 Links: 1 Aess: (0644/-rw-r-r-) Uid: ( 0/ root) Gid: ( 0/ root) Aess: xx-03-17 10:58:01.328805868 +0800 Modify: xx-03-17 10:58:01.328805868 +0800 Change: xx-03-17 10:58:01.328805868 +0800 Birth: - 新创建的目录和文件的atime/mtime/ctime都是一样的。 打开a.txt,随便输入点内容然后保存。 # stat a.txt File: a.txt Size: 3 Blocks: 8 IO Block: 4096 regular file Device: ca01h/51713d Inode: 1050208 Links: 1 Aess: (0644/-rw-r-r-) Uid: ( 0/ root) Gid: ( 0/ root) Aess: xx-03-17 11:02:19.619836157 +0800 Modify: xx-03-17 11:02:22.399782635 +0800 Change: xx-03-17 11:02:22.423782143 +0800 Birth: - vi a.txt的时候会修改文件的atime,输入内容保存后会修改mtime,同时因为文件的属性变更了(比如文件大小就变了),所以ctime也会改变。 修改文件的属性,ctime变化,mtime和atime不变。 # stat a.txt File: a.txt Size: 9 Blocks: 8 IO Block: 4096 regular file Device: ca01h/51713d Inode: 1050208 Links: 1 Aess: (0664/-rw-rw-r-) Uid: ( 0/ root) Gid: ( 0/ root) Aess: xx-03-17 11:02:19.619836157 +0800 Modify: xx-03-17 11:02:22.399782635 +0800 Change: xx-03-17 11:07:10.114234176 +0800 Birth: - 修改内容一定会改变atime吗?答案是否! # echo world a.txt # stat a.txt File: a.txt Size: 9 Blocks: 8 IO Block: 4096 regular file Device: ca01h/51713d Inode: 1050208 Links: 1 Aess: (0644/-rw-r-r-) Uid: ( 0/ root) Gid: ( 0/ root) Aess: xx-03-17 11:02:19.619836157 +0800 Modify: xx-03-17 11:09:07.980591047 +0800 Change: xx-03-17 11:09:07.980591047 +0800 Birth: - touch指令的作用就是用于改变文件的时间戳,touch命令的语法格式如下: touch 选项. filename. 选项与参数: -a : 仅修订 atime; -c : 仅修改档案的时间,若该档案不存在则不建立新档案; -d : 后面可以接欲修订的日期而不用目前的日期,也可以使用 -date=日期或时间 -m : 仅修改 mtime ; -t : 后面可以接欲修订的时间而不用目前的时间,格式为YYMMDDhhmm -r : 把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同 . 示例演示 # stat a.txt File: a.txt Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: ca01h/51713d Inode: 1050217 Links: 1 Aess: (0644/-rw-r-r-) Uid: ( 0/ root) Gid: ( 0/ root) Aess: xx-03-18 09:30:49.965240705 +0800 Modify: xx-03-18 09:30:49.965240705 +0800 Change: xx-03-18 09:30:49.965240705 +0800 Birth: - 先通过touch创建a.txt,如果已经存在则会修改文件的atime/mtime/ctime。 # stat a.txt File: a.txt Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: ca01h/51713d Inode: 1050217 Links: 1 Aess: (0644/-rw-r-r-) Uid: ( 0/ root) Gid: ( 0/ root) Aess: xx-03-18 09:31:43.584234285 +0800 Modify: xx-03-18 09:31:43.584234285 +0800 Change: xx-03-18 09:31:43.584234285 +0800 Birth: - 再touch a.txt,发现atime/mtime/ctime都发生变化了, # stat a.txt File: a.txt Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: ca01h/51713d Inode: 1050217 Links: 1 Aess: (0644/-rw-r-r-) Uid: ( 0/ root) Gid: ( 0/ root) Aess: xx-03-18 09:32:01.459898755 +0800 Modify: xx-03-18 09:31:43.584234285 +0800 Change: xx-03-18 09:32:01.459898755 +0800 Birth: - 使用touch -a a.txt,只有atime和ctime发生变化了,mtime保存不变。 # stat a.txt File: a.txt Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: ca01h/51713d Inode: 1050217 Links: 1 Aess: (0644/-rw-r-r-) Uid: ( 0/ root) Gid: ( 0/ root) Aess: xx-03-18 09:32:01.459898755 +0800 Modify: xx-03-18 09:32:22.591502109 +0800 Change: xx-03-18 09:32:22.591502109 +0800 Birth: - 使用touch -m a.txt,只有mtime和ctime发生变化了,atime保存不变。 任何情况下,使用touch指令,文件的ctime都会发生改变。以上经过touch指令后,atime/mtime/ctime的值都是当前时间点的值,通过touch指令还可以随意指定时间戳。 File: b.txt Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: ca01h/51713d Inode: 1050218 Links: 1 Aess: (0644/-rw-r-r-) Uid: ( 0/ root) Gid: ( 0/ root) Aess: xx-03-16 09:38:49.261034132 +0800 Modify: xx-03-16 09:38:49.261034132 +0800 Change: xx-03-18 09:38:49.256243241 +0800 Birth: - touch -d 通过指定一个表示时间的字符串来当做当前时间,这个格式比较自由,只要是能表示时间的都可以,例如”xx-02-28 16:21:42、”next Thursday”、”2 days ago”等。 File: c.txt Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: ca01h/51713d Inode: 1050219 Links: 1 Aess: (0644/-rw-r-r-) Uid: ( 0/ root) Gid: ( 0/ root) Aess: xx-01-01 12:12:30.000000000 +0800 Modify: xx-01-01 12:12:30.000000000 +0800 Change: xx-03-18 09:39:45.983178168 +0800 Birth: - # touch -t 01011212 d.txt & stat d.txt File: d.txt Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: ca01h/51713d Inode: 1050220 Links: 1 Aess: (0644/-rw-r-r-) Uid: ( 0/ root) Gid: ( 0/ root) Aess: xx-01-01 12:12:00.000000000 +0800 Modify: xx-01-01 12:12:00.000000000 +0800 Change: xx-03-18 09:41:59.092678768 +0800 Birth: - touch -t 指令后面的时间戳格式为:CCYYMMDDhhmm.ss 同样的,ctime始终是当前时间 ctime,mtime,atime的区别 当你同熟练的UNIX用户进行交谈时,你经常会听到他们傲慢地讲出术语“改变时间(change time)”和“修改时间(modification time)”。对于许多人(和许多字典而言),改变和修改是相同的。这里会有什么不同那? 改变和修改之间的区别在于是改某个组件的标签还是更改它的内容。如果有人说chmod a-w myfile,那么这是一个改变;如果有人说echo foo myfile,那么 这是一个修改。改变是文件的索引节点发生了改变;修改是文本本身的内容发生了变化。文件的修改时间也叫时间标志 (timestamp). 只要讨论改变时间和修改时间,就不可能不提到“访问时间(aess time)”.访问时间是文件最后一次被读取的时间。因此阅读一个文件会更新它的访问时间,当它的改变时间并没有变化(有关文件的信息没有被改变),它的修改时间也同样如此(文件本身没有被改变) 有时,在许多地方改变时间或者“ctime”被错误地写成“创建时间”,包括某些UNIX参考手册。不要相信他们 下面是我man出来的内容,仅供参考! st_atime Time when file data was last aessed. Changed by the following functions: creat(), mknod(), pipe(), utime(2), and read(2). st_mtime Time when data was last modified. Changed by the fol- lowing functions: creat(), mknod(), pipe(), utime(), and write(2). st_ctime Time when file status was last changed. Changed by the following functions: chmod(), chown(), creat(), link(2), mknod(), pipe(), unlink(2), utime(), and write(). ls显示出的time应该是mtime。 touch后,文件的三个时间应该都会改变,可以试一试。 问题

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论