元数据定义
MetaData元数据是描述一个文件的特征的系统数据,诸如访问权限、文件拥有者以及文件数据。
在集群文件系统中,也会看到DateNode和MetaNode,后者就是描述文件在集群中的位置。
不论在单机环节或集群环境,用户操作一个文件前,必须首先得到它的元数据,才能定位到文件的位置并且得到文件的内容或相关属性。
查看命令:stat
[root@oracle tmp]# stat profile
File: 'profile'
Size: 1579 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2228228 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 13:25:00.903142426 +0800
Modify: 2020-04-22 13:24:57.440986257 +0800
Change: 2020-04-22 13:24:57.441986302 +0800
[root@oracle tmp]# touch test10; stat test10 ; echo "Nowtime" "`date +%F" "%T.%N" "%z`"
File: ’test10'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 2228238 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 18:11:59.903022404 +0800
Modify: 2020-04-22 18:11:59.903022404 +0800
Change: 2020-04-22 18:11:59.903022404 +0800
Nowtime 2020-04-22 18:11:59.914273670 +0800
如何修改文件的时间戳信息?
命令touch可以同时刷新元数据的时间戳信息
File: 'profile'
Size: 1827 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2228228 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 21:12:37.165113482 +0800
Modify: 2020-04-22 21:13:47.816084697 +0800
Change: 2020-04-22 21:21:30.586551224 +0800
[root@oracle tmp]# touch profile
[root@oracle tmp]# stat profile
File: 'profile'
Size: 1827 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2228228 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 21:26:33.237331074 +0800
Modify: 2020-04-22 21:26:33.237331074 +0800
Change: 2020-04-22 21:26:33.237331074 +0800
或者利用touch的参数修改指定时间戳的信息:
touch命令 格式:touch [OPTION]… FILE…
-a 仅改变 atime和ctime
-m 仅改变 mtime和ctime
-t [[CC]YY]MMDDhhmm[.ss]
指定atime和mtime的时间戳
不同的文件操作如何影Metadata?
mv操作 影响ctime和inode (Device可能会更新 )
[root@oracle tmp]# stat profile
File: 'profile'
Size: 1579 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2228228 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 13:25:00.903142426 +0800
Modify: 2020-04-22 13:24:57.440986257 +0800
Change: 2020-04-22 13:24:57.441986302 +0800
[root@oracle tmp]# mv profile /home/
[root@oracle tmp]# ls /home/profile
/home/profile
[root@oracle tmp]# stat /home/profile
File: '/home/profile'
Size: 1579 Blocks: 8 IO Block: 4096 regular file
Device: fd02h/64770d Inode: 881 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 13:25:00.903142426 +0800
Modify: 2020-04-22 13:24:57.440986257 +0800
Change: 2020-04-22 17:29:29.229779538 +0800
创建链接 影响 ctime和Links
[root@oracle tmp]# stat profile
File: 'profile'
Size: 1823 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2228228 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 17:33:26.150897074 +0800
Modify: 2020-04-22 17:33:26.151897121 +0800
Change: 2020-04-22 17:33:26.151897121 +0800
[root@oracle tmp]# ln profile profile.link
[root@oracle tmp]# stat profile
File: 'profile'
Size: 1823 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2228228 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 17:33:26.150897074 +0800
Modify: 2020-04-22 17:33:26.151897121 +0800
Change: 2020-04-22 17:33:41.302607186 +0800
echo 重定向 影响mtime和ctime(size、Blocks随着内容的增加会放大)
[root@oracle tmp]# stat profile
File: 'profile'
Size: 1823 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2228228 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 17:33:26.150897074 +0800
Modify: 2020-04-22 17:33:26.151897121 +0800
Change: 2020-04-22 17:33:41.302607186 +0800
[root@oracle tmp]# echo a >> profile
[root@oracle tmp]# stat profile
File: 'profile'
Size: 1825 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2228228 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 17:33:26.150897074 +0800
Modify: 2020-04-22 21:11:06.772137866 +0800
Change: 2020-04-22 21:11:06.772137866 +0800
vi不修改内容后退出 只会影响atime
vi修改内容后退出 影响mtime和ctime (size、Blocks随着内容的增加会放大)
[root@oracle tmp]# stat profile
File: 'profile'
Size: 1825 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2228228 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 21:12:37.165113482 +0800
Modify: 2020-04-22 21:11:06.772137866 +0800
Change: 2020-04-22 21:11:06.772137866 +0800
[root@oracle tmp]# vi profile
[root@oracle tmp]# stat profile
File: 'profile'
Size: 1827 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2228228 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 21:12:37.165113482 +0800
Modify: 2020-04-22 21:13:47.816084697 +0800
Change: 2020-04-22 21:13:47.818084782 +0800
拷贝操作 影响atime
[root@oracle tmp]# stat profile
File: 'profile'
Size: 1827 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2228228 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 21:26:33.237331074 +0800
Modify: 2020-04-22 21:26:33.237331074 +0800
Change: 2020-04-22 21:26:33.237331074 +0800
[root@oracle tmp]# cp profile profile.bakbak
[root@oracle tmp]# stat profile
File: 'profile'
Size: 1827 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2228228 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-22 21:35:38.026422960 +0800
Modify: 2020-04-22 21:26:33.237331074 +0800
Change: 2020-04-22 21:26:33.237331074 +0800
小结: