CentOS中可以通过stat查看文件的元数据
[baby@xiaoxiaoabc]$stathoney
File:`honey'
Size:25Blocks:8IOBlock:4096regularfile
Device:806h/2054dInode:131076Links:1
Access:(0664/-rw-rw-r--)Uid:(500/baby)Gid:(500/baby)
Access:2015-03-3010:27:51.851234105+0800
Modify:2015-03-3010:44:58.144226717+0800
Change:2015-03-3010:44:58.146226803+0800
Access:最后访问时间
Modify:最后修改时间
Change:状态更改时间(由系统维护,无法随意修改)
touch-a:仅更新Accesstime(同时更新Change为currenttime)
touch-m:仅更新Modifytime(同时更新Change为currenttime)
touch-c:不创建新文件
touch-t:使用指定的时间更新时间戳(仅更改Accesstime与Modifytime,Changetime更新为currenttime)
例:touch-t[[CC]YY]MMDDhhmm[.ss]filename
[root@xiaoxiaocde]#touch-t199906121808honey
[root@xiaoxiaocde]#stathoney
File:`honey'
Size:25Blocks:8IOBlock:4096regularfile
Device:806h/2054dInode:131076Links:1
Access:(0664/-rw-rw-r--)Uid:(500/baby)Gid:(500/baby)
Access:1999-06-1218:08:00.000000000+0800
Modify:1999-06-1218:08:00.000000000+0800
Change:2015-03-3013:31:40.064221158+0800
当文件的任何数据改变时(包括文件的数据和元数据),Change会更新,对文件重命名(mv),移动(mv)或者复制时(cp-a),系统都会更新文件的Changetime。当文件的内容被修改时Modify和Change会同时更新。当Changetime更新后,第一次访问该文件,系统会更新Accesstime(仅更新Accesstime),之后对该文件的访问,将不会更新Accesstime。
[baby@xiaoxiaocde]$touchhoney
[baby@xiaoxiaocde]$stathoney
File:`honey'
Size:25Blocks:8IOBlock:4096regularfile
Device:806h/2054dInode:131076Links:1
Access:(0664/-rw-rw-r--)Uid:(500/baby)Gid:(500/baby)
Access:2015-03-3011:24:47.041225726+0800
Modify:2015-03-3011:24:47.041225726+0800
Change:2015-03-3011:24:47.041225726+0800
[baby@xiaoxiaocde]$cathoney&>/dev/null
[baby@xiaoxiaocde]$stathoney
File:`honey'
Size:25Blocks:8IOBlock:4096regularfile
Device:806h/2054dInode:131076Links:1
Access:(0664/-rw-rw-r--)Uid:(500/baby)Gid:(500/baby)
Access:2015-03-3011:25:16.401228081+0800
Modify:2015-03-3011:24:47.041225726+0800
Change:2015-03-3011:24:47.041225726+0800
用touch更新时间戳后的第一次访问,Accesstime更新了,下面是第二次访问之后的元数据,Accesstime并没有更新。
[baby@xiaoxiaocde]$cathoney&>/dev/null
[baby@xiaoxiaocde]$stathoney
File:`honey'
Size:25Blocks:8IOBlock:4096regularfile
Device:806h/2054dInode:131076Links:1
Access:(0664/-rw-rw-r--)Uid:(500/baby)Gid:(500/baby)
Access:2015-03-3011:25:16.401228081+0800
Modify:2015-03-3011:24:47.041225726+0800
Change:2015-03-3011:24:47.041225726+0800
tar或者各种压缩命令在解压出来时都会更新文件的Changetime,若想要不更改Changetime备份文件可以使用dd命令(dd命令在复制单个文件时,会更新时间戳,在备份整个分区时,会保留文件的所有属性),过程如下:
新建一个分区sda10,不用格式化,挂载到/media/sda10。
[root@xiaoxiaocde]#ll/dev/sda10
brw-rw----1rootdisk8,10Mar3012:58/dev/sda10
[root@xiaoxiaoabc]#ddif=/dev/sda6of=/dev/sda10&(/dev/sda6挂载在/tmp下)
[1]5917
[root@xiaoxiaoabc]#mount/dev/sda10/media/sda10/
[root@xiaoxiaocde]#stat/media/sda10/cde/honey/tmp/cde/honey
File:`/media/sda10/cde/honey'
Size:25Blocks:8IOBlock:4096regularfile
Device:80ah/2058dInode:131076Links:1
Access:(0664/-rw-rw-r--)Uid:(500/baby)Gid:(500/baby)
Access:2015-03-3011:25:16.401228081+0800
Modify:2015-03-3011:24:47.041225726+0800
Change:2015-03-3011:24:47.041225726+0800
File:`/tmp/cde/honey'
Size:25Blocks:8IOBlock:4096regularfile
Device:806h/2054dInode:131076Links:1
Access:(0664/-rw-rw-r--)Uid:(500/baby)Gid:(500/baby)
Access:2015-03-3011:25:16.401228081+0800
Modify:2015-03-3011:24:47.041225726+0800
Change:2015-03-3011:24:47.041225726+0800
两个文件的元数据一模一样。