瀏覽量:27次
CentOS中可以通過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:最后訪問時(shí)間
Modify:最后修改時(shí)間
Change:狀態(tài)更改時(shí)間(由系統(tǒng)維護(hù),無法隨意修改)
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更新后,第一次訪問該文件,系統(tǒng)會(huì)更新Access time(僅更新Access time),之后對(duì)該文件的訪問,將不會(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í)間戳后的第一次訪問,Access time更新了,下面是第二次訪問之后的元數(shù)據(jù),Access time并沒有更新。
[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或者各種壓縮命令在解壓出來時(shí)都會(huì)更新文件的Change time,若想要不更改Change time備份文件可以使用dd命令(dd命令在復(fù)制單個(gè)文件時(shí),會(huì)更新時(shí)間戳,在備份整個(gè)分區(qū)時(shí),會(huì)保留文件的所有屬性),過程如下:
新建一個(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ù)一模一樣。
[聲明]本網(wǎng)轉(zhuǎn)載網(wǎng)絡(luò)媒體稿件是為了傳播更多的信息,此類稿件不代表本網(wǎng)觀點(diǎn),本網(wǎng)不承擔(dān)此類稿件侵權(quán)行為的連帶責(zé)任。故此,如果您發(fā)現(xiàn)本網(wǎng)站的內(nèi)容侵犯了您的版權(quán),請(qǐng)您的相關(guān)內(nèi)容發(fā)至此郵箱【779898168@qq.com】,我們?cè)诖_認(rèn)后,會(huì)立即刪除,保證您的版權(quán)。
官網(wǎng)優(yōu)化
整站優(yōu)化
渠道代理
400-655-5776