CentOS中可以通過(guò)stat查看文件的元數(shù)據(jù)
[baby@xiaoxiao abc]$ stat honey
File: `honey'
Size: 25 Blocks: 8 IO Block: 4096 regular file
Device: 806h/2054d Inode: 131076 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 500/ baby) Gid: ( 500/ baby)
Access: 2015-03-30 10:27:51.851234105 +0800
Modify: 2015-03-30 10:44:58.144226717 +0800
Change: 2015-03-30 10:44:58.146226803 +0800
Access:最后訪問(wèn)時(shí)間
Modify:最后修改時(shí)間
Change:狀態(tài)更改時(shí)間(由系統(tǒng)維護(hù),無(wú)法隨意修改)
touch -a :僅更新Access time(同時(shí)更新Change為current time)
touch -m:僅更新Modify time(同時(shí)更新Change為current time)
touch -c:不創(chuàng)建新文件
touch -t:使用指定的時(shí)間更新時(shí)間戳(僅更改Access time與Modify time,Change time更新為current time)
例:touch -t [[CC]YY]MMDDhhmm[.ss] filename
[root@xiaoxiao cde]# touch -t 199906121808 honey
[root@xiaoxiao cde]# stat honey
File: `honey'
Size: 25 Blocks: 8 IO Block: 4096 regular file
Device: 806h/2054d Inode: 131076 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 500/ baby) Gid: ( 500/ baby)
Access: 1999-06-12 18:08:00.000000000 +0800
Modify: 1999-06-12 18:08:00.000000000 +0800
Change: 2015-03-30 13:31:40.064221158 +0800
當(dāng)文件的任何數(shù)據(jù)改變時(shí)(包括文件的數(shù)據(jù)和元數(shù)據(jù)),Change會(huì)更新,對(duì)文件重命名(mv),移動(dòng)(mv)或者復(fù)制時(shí)(cp -a),系統(tǒng)都會(huì)更新文件的Change time。當(dāng)文件的內(nèi)容被修改時(shí)Modify和Change會(huì)同時(shí)更新。當(dāng)Change time更新后,第一次訪問(wèn)該文件,系統(tǒng)會(huì)更新Access time(僅更新Access time),之后對(duì)該文件的訪問(wèn),將不會(huì)更新Access time。
[baby@xiaoxiao cde]$ touch honey
[baby@xiaoxiao cde]$ stat honey
File: `honey'
Size: 25 Blocks: 8 IO Block: 4096 regular file
Device: 806h/2054d Inode: 131076 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 500/ baby) Gid: ( 500/ baby)
Access: 2015-03-30 11:24:47.041225726 +0800
Modify: 2015-03-30 11:24:47.041225726 +0800
Change: 2015-03-30 11:24:47.041225726 +0800
[baby@xiaoxiao cde]$ cat honey > /dev/null
[baby@xiaoxiao cde]$ stat honey
File: `honey'
Size: 25 Blocks: 8 IO Block: 4096 regular file
Device: 806h/2054d Inode: 131076 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 500/ baby) Gid: ( 500/ baby)
Access: 2015-03-30 11:25:16.401228081 +0800
Modify: 2015-03-30 11:24:47.041225726 +0800
Change: 2015-03-30 11:24:47.041225726 +0800
用touch更新時(shí)間戳后的第一次訪問(wèn),Access time更新了,下面是第二次訪問(wèn)之后的元數(shù)據(jù),Access time并沒(méi)有更新。
[baby@xiaoxiao cde]$ cat honey > /dev/null
[baby@xiaoxiao cde]$ stat honey
File: `honey'
Size: 25 Blocks: 8 IO Block: 4096 regular file
Device: 806h/2054d Inode: 131076 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 500/ baby) Gid: ( 500/ baby)
Access: 2015-03-30 11:25:16.401228081 +0800
Modify: 2015-03-30 11:24:47.041225726 +0800
Change: 2015-03-30 11:24:47.041225726 +0800
tar或者各種壓縮命令在解壓出來(lái)時(shí)都會(huì)更新文件的Change time,若想要不更改Change time備份文件可以使用dd命令(dd命令在復(fù)制單個(gè)文件時(shí),會(huì)更新時(shí)間戳,在備份整個(gè)分區(qū)時(shí),會(huì)保留文件的所有屬性),過(guò)程如下:
新建一個(gè)分區(qū)sda10,不用格式化,掛載到/media/sda10。
[root@xiaoxiao cde]# ll /dev/sda10
brw-rw---- 1 root disk 8, 10 Mar 30 12:58 /dev/sda10
[root@xiaoxiao abc]# dd if=/dev/sda6 of=/dev/sda10 (/dev/sda6掛載在/tmp下)
[1] 5917
[root@xiaoxiao abc]# mount /dev/sda10 /media/sda10/
[root@xiaoxiao cde]# stat /media/sda10/cde/honey /tmp/cde/honey
File: `/media/sda10/cde/honey'
Size: 25 Blocks: 8 IO Block: 4096 regular file
Device: 80ah/2058d Inode: 131076 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 500/ baby) Gid: ( 500/ baby)
Access: 2015-03-30 11:25:16.401228081 +0800
Modify: 2015-03-30 11:24:47.041225726 +0800
Change: 2015-03-30 11:24:47.041225726 +0800
File: `/tmp/cde/honey'
Size: 25 Blocks: 8 IO Block: 4096 regular file
Device: 806h/2054d Inode: 131076 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 500/ baby) Gid: ( 500/ baby)
Access: 2015-03-30 11:25:16.401228081 +0800
Modify: 2015-03-30 11:24:47.041225726 +0800
Change: 2015-03-30 11:24:47.041225726 +0800
兩個(gè)文件的元數(shù)據(jù)一模一樣。