日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
詳解Linux文件的三個(gè)時(shí)間

Linux文檔的時(shí)間一般分三種:Access time-atime(訪問時(shí)間)、Modification time-mtime(內(nèi)容修改時(shí)間)、change-ctime(inode更改時(shí)間),下面為大家詳細(xì)講解一下Linux中文件的三種時(shí)間。

成都創(chuàng)新互聯(lián)公司于2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站建設(shè)、成都網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢想脫穎而出為使命,1280元大石橋做網(wǎng)站,已為上家服務(wù),為大石橋各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:028-86922220

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

    1. 簡名 全名 中文名 含義
      atime access time 訪問時(shí)間 文件中的數(shù)據(jù)庫最后被訪問的時(shí)間
      mtime modify time 修改時(shí)間 文件內(nèi)容被修改的最后時(shí)間
      ctime change 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                             #列出文件的atimetotal 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                #列出ctimetotal 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             | -           |
  +-------------------------------------------------+

本文名稱:詳解Linux文件的三個(gè)時(shí)間
標(biāo)題路徑:http://www.5511xx.com/article/dhggojs.html