最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

linux中文件的三種time(atime,mtime,ctime)的用法

 更新時(shí)間:2023年08月27日 14:25:38   作者:LinuxPanda  
linux下文件有3個(gè)時(shí)間的,分別是atime,mtime,ctime,有些小伙伴對這3個(gè)時(shí)間還是比較迷茫和困惑的,所以小編為大家整理了下,希望對大家有所幫助

1.這三個(gè)time的含義

簡名全名中文名含義
atimeaccess time訪問時(shí)間文件中的數(shù)據(jù)庫最后被訪問的時(shí)間
mtimemodify time修改時(shí)間文件內(nèi)容被修改的最后時(shí)間
ctimechange time變化時(shí)間文件的元數(shù)據(jù)發(fā)生變化。比如權(quán)限,所有者等

2.如何查看這3個(gè)time

[root@centos7 time]# pwd
/app/time
[root@centos7 time]# ll
total 8
-rw-------. 1 root root 1933 Nov 11 08:14 anaconda-ks.cfg
-rw-r--r--. 1 root root   59 Nov 11 08:15 issue
[root@centos7 time]# stat issue 
  File: ‘issue'
  Size: 59            Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d    Inode: 261123      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:etc_runtime_t:s0
Access: 2017-11-11 08:15:05.650986739 +0800
Modify: 2017-11-11 08:15:05.650986739 +0800
Change: 2017-11-11 08:15:05.650986739 +0800
 Birth: -
[root@centos7 time]# ls -l                               #默認(rèn)的ls -l顯示的是mtime     
total 8
-rw-------. 1 root????? root 1933 Nov 11 08:14 anaconda-ks.cfg
-rw-r--r--. 1 zhaojiedi root?? 71 Nov 11 09:05 issue
[root@centos7 time]# ls -l --time=atime                             #列出文件的atime
total 8
-rw-------. 1 root????? root 1933 Nov 11 08:14 anaconda-ks.cfg
-rw-r--r--. 1 zhaojiedi root?? 71 Nov 11 09:12 issue
[root@centos7 time]# ls -l --time=ctime                #列出ctime
total 8
-rw-------. 1 root????? root 1933 Nov 11 08:14 anaconda-ks.cfg
-rw-r--r--. 1 zhaojiedi root?? 71 Nov 11 09:03 issue

3.三個(gè)time的測試

3.1測試準(zhǔn)備工作

測試前,我們需要先關(guān)閉文件系統(tǒng)的relatime特性。這個(gè)隨后在說,具體操作如下。

[root@centos7 time]# mount -o remount,strictatime /app  # 重新掛載我們的/app,并修改文件系統(tǒng)工作在嚴(yán)格atime上,也就是不啟用了默認(rèn)的relatime支持。
[root@centos7 time]# mount |grep /app                   #查看我們的修改
/dev/sda5 on /app type ext4 (rw,seclabel,data=ordered)

3.2讀取文件測試

[root@centos7 time]# stat issue                             #先獲取3個(gè)時(shí)間
  File: ‘issue'
  Size: 59            Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d    Inode: 261123      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:etc_runtime_t:s0
Access: 2017-11-11 08:15:05.650986739 +0800
Modify: 2017-11-11 08:15:05.650986739 +0800
Change: 2017-11-11 08:15:05.650986739 +0800
 Birth: -
[root@centos7 time]# cat issue                             #讀取下
\S
Kernel \r on an \m
tty:   \l
hostname:   \n
time:    \t
[root@centos7 time]# stat issue                #再次查看3個(gè)時(shí)間
  File: ‘issue'
  Size: 59            Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d    Inode: 261123      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:etc_runtime_t:s0
Access: 2017-11-11 08:57:40.858948780 +0800
Modify: 2017-11-11 08:15:05.650986739 +0800
Change: 2017-11-11 08:15:05.650986739 +0800
 Birth: -

通過上面的分析,我們可以看出來,在使用cat讀取文件后,文件的atime發(fā)生了改變。其他的沒有改變。

3.3修改文件測試

[root@centos7 time]# stat issue                           #先獲取下3個(gè)time
  File: ‘issue'
  Size: 65            Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d    Inode: 261123      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:etc_runtime_t:s0
Access: 2017-11-11 09:03:49.080931626 +0800
Modify: 2017-11-11 09:04:16.881930331 +0800
Change: 2017-11-11 09:04:16.881930331 +0800
 Birth: -
[root@centos7 time]# echo "hello" >> issue                #修改文件
[root@centos7 time]# stat issue                 #再次查看三個(gè)time
  File: ‘issue'
  Size: 71            Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d    Inode: 261123      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:etc_runtime_t:s0
Access: 2017-11-11 09:03:49.080931626 +0800
Modify: 2017-11-11 09:05:07.775927960 +0800
Change: 2017-11-11 09:05:07.775927960 +0800
 Birth: -

通過上面的實(shí)驗(yàn),我們可以看出來,寫文件操作不會(huì)導(dǎo)致atime(訪問時(shí)間)的修改,但是mtime和ctime會(huì)發(fā)生修改。mtime修改了我們可以理解的,畢竟我們修改了文件的,

那為何ctime也修改了呢, 仔細(xì)可以發(fā)現(xiàn)我們文件的大小發(fā)生了變化,也就是元數(shù)據(jù)發(fā)生了變化,所以ctime也是要變化的。

3.4修改文件所有者測試

[root@centos7 time]# stat issue                                          #先查看下3個(gè)time 
  File: ‘issue'
  Size: 71            Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d    Inode: 261123      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:etc_runtime_t:s0
Access: 2017-11-11 09:03:49.080931626 +0800
Modify: 2017-11-11 09:05:07.775927960 +0800
Change: 2017-11-11 09:05:07.775927960 +0800
 Birth: -
[root@centos7 time]# chown zhaojiedi issue                              #修改權(quán)限
[root@centos7 time]# stat issue                         #再次查看3個(gè)時(shí)間
  File: ‘issue'
  Size: 71            Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d    Inode: 261123      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/zhaojiedi)   Gid: (    0/    root)
Context: unconfined_u:object_r:etc_runtime_t:s0
Access: 2017-11-11 09:03:49.080931626 +0800
Modify: 2017-11-11 09:05:07.775927960 +0800
Change: 2017-11-11 09:12:42.076906795 +0800
 Birth: -

通過上面的實(shí)驗(yàn),我們可以看出來,修改了權(quán)限后,文件ctime發(fā)生了變化。

4.說說relatime

常用命令對三個(gè)time的修改情況我們上面的測試,可以看出來,每次訪問文件都會(huì)更新atime,這是很耗時(shí)的,尤其在web服務(wù)器上,大量用戶只是訪問html頁面,完全沒有必要修改atime。

從kernel2.6.29開始,文件系統(tǒng)默認(rèn)集成了一個(gè)relatime的屬性。

那么啥時(shí)候更新atime呢? 有2種情況會(huì)更新atime,第一種是mtime比atime新,第二種是上次訪問是1天前的了。

5.常用命令對三個(gè)time的修改情況

上面我們做了3個(gè)測試,我們也對atime,mtime,ctime有了一定的了解。網(wǎng)上有人已經(jīng)做了好多測試如下表。

+-------------------------------------------------+
   |               |  timestamps marked for update   |
   |    syscall    |---------------------------------|
   |               |       file        | parent dir  |
   |---------------+-------------------+-------------|
   | [2]chdir      |                   |             |
   |---------------| -                 | -           |
   | [3]fchdir     |                   |             |
   |---------------+-------------------+-------------|
   | [4]chmod      |                   |             |
   |---------------| ctime             | -           |
   | [5]fchmod     |                   |             |
   |---------------+-------------------+-------------|
   | [6]chown      |                   |             |
   |---------------|                   |             |
   | [7]fchown     | ctime             | -           |
   |---------------|                   |             |
   | [8]lchown     |                   |             |
   |---------------+-------------------+-------------|
   | [9]close      | -                 | -           |
   |---------------+-------------------+-------------|
   | [10]creat     | atime,ctime,mtime | ctime,mtime |
   |---------------+-------------------+-------------|
   | [11]execve    | atime             | -           |
   |---------------+-------------------+-------------|
   | [12]fcntl     | -                 | -           |
   |---------------+-------------------+-------------|
   | [13]ftruncate |                   |             |
   |---------------| ctime,mtime       | -           |
   | [14]truncate  |                   |             |
   |---------------+-------------------+-------------|
   | [15]fstat     |                   |             |
   |---------------|                   |             |
   | [16]stat      | -                 | -           |
   |---------------|                   |             |
   | [17]lstat     |                   |             |
   |---------------+-------------------+-------------|
   | [18]fsync     |                   |             |
   |---------------| -                 | -           |
   | [19]fdatasync |                   |             |
   |---------------+-------------------+-------------|
   | [20]link      | ctime             | ctime,mtime |
   |---------------+-------------------+-------------|
   | [21]lseek     | -                 | -           |
   |---------------+-------------------+-------------|
   | [22]mknod     | atime,ctime,mtime | ctime,mtime |
   |---------------+-------------------+-------------|
   | [23]mkdir     | atime,ctime,mtime | ctime,mtime |
   |---------------+-------------------+-------------|
   | [24]mmap      | *                 | -           |
   |---------------+-------------------+-------------|
   | [25]munmap    | -                 | -           |
   |---------------+-------------------+-------------|
   | [26]msync     | *                 | -           |
   |---------------+-------------------+-------------|
   | [27]open      | *                 | *           |
   |---------------+-------------------+-------------|
   | [28]pread     |                   |             |
   |---------------|                   |             |
   | [29]read      | atime             | -           |
   |---------------|                   |             |
   | [30]readv     |                   |             |
   |---------------+-------------------+-------------|
   | [31]pwrite    |                   |             |
   |---------------|                   |             |
   | [32]write     | ctime,mtime       | -           |
   |---------------|                   |             |
   | [33]writev    |                   |             |
   |---------------+-------------------+-------------|
   | [34]rename    | implementation    | ctime,mtime |
   |---------------+-------------------+-------------|
   | [35]rmdir     | -                 | ctime,mtime |
   |---------------+-------------------+-------------|
   | [36]readlink  | *                 | -           |
   |---------------+-------------------+-------------|
   | [37]readdir   | atime             | -           |
   |---------------+-------------------+-------------|
   | readahead     | ?                 | ?           |
   |---------------+-------------------+-------------|
   | [38]symlink   | *                 | *           |
   |---------------+-------------------+-------------|
   | sendfile      | ?                 | ?           |
   |---------------+-------------------+-------------|
   | [39]unlink    | -                 | ctime,mtime |
   |---------------+-------------------+-------------|
   | [40]utime     | ctime             | -           |
   +-------------------------------------------------+

到此這篇關(guān)于linux中文件的三種time(atime,mtime,ctime)的用法的文章就介紹到這了,更多相關(guān)linux time內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

顺义区| 平安县| 尼木县| 沛县| 清水河县| 沛县| 荣成市| 洛宁县| 繁昌县| 商南县| 松溪县| 昭苏县| 黄冈市| 蕉岭县| 汉中市| 翁牛特旗| 阿合奇县| 万源市| 长治市| 桃源县| 孝义市| 军事| 班戈县| 玉溪市| 湾仔区| 贵南县| 黎平县| 渭南市| 荔浦县| 沾化县| 南陵县| 崇文区| 麻阳| 定边县| 莱芜市| 彰化县| 衡阳县| 乳山市| 原平市| 通道| 额尔古纳市|