文件组成
一个文件通常有两部分组成:
- 元数据(metadata):使用 stat 命令查看
- 数据(data):使用文件查看命令查看,如 cat、tac、less等
stat
用于显示文件的状态信息。stat命令的输出信息比ls命令的输出信息要更详细。
stat:display file or file system status
用于显示文件的状态信息
命令格式:
stat FILE...
时间戳:
最近访问 access time
最近更改 modify time
最近改动 change time
touch
有两个功能:一是用于把已存在文件的时间标签更新为系统当前的时间(默认方式),它们的数据将原封不动地保留下来;二是用来创建新的空文件。
touch:change file timestamps
仅修改access time 和 modify time
命令格式:
touch [OPTION]... FILE...
修改时间戳,当文件不存在时,会进行创建
常用选项:
-c: 指定的文件路径不存在时不予创建
-a: 仅修改access time
-m:仅修改modify time
-t STAMP:使用指定的日期时间,而非现在的时间
[[CC]YY]MMDDhhmm[.ss]
示例
# touch 1.txt # 新创建一个 1.txt 的文件
# stat 1.txt # 查看 1.txt 的元数据
File: '1.txt'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fc00h/64512d Inode: 132637 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-25 17:31:36.308297905 +0800
Modify: 2019-05-25 17:31:36.308297905 +0800
Change: 2019-05-25 17:31:36.308297905 +0800
Birth: -
# cat 1.txt # 查看 1.txt 的内容
# stat 1.txt # cat 可以更改文件的 access time
File: '1.txt'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fc00h/64512d Inode: 132637 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-25 18:47:49.491219278 +0800
Modify: 2019-05-25 17:31:36.308297905 +0800
Change: 2019-05-25 17:31:36.308297905 +0800
Birth: -
# ll >> 1.txt # 对文件 1.txt 的内容进行修改
# stat 1.txt # 文件的 modify time 和 change time 更新
File: '1.txt'
Size: 540 Blocks: 8 IO Block: 4096 regular file
Device: fc00h/64512d Inode: 132637 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-25 18:47:49.491219278 +0800
Modify: 2019-05-25 18:48:21.226698375 +0800
Change: 2019-05-25 18:48:21.226698375 +0800
Birth: -
# touch -a 1.txt # 修改文件的 access time
# stat 1.txt
File: '1.txt'
Size: 540 Blocks: 8 IO Block: 4096 regular file
Device: fc00h/64512d Inode: 132637 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-25 18:52:24.794779505 +0800
Modify: 2019-05-25 18:48:21.226698375 +0800
Change: 2019-05-25 18:52:24.794779505 +0800
Birth: -
# touch -m 1.txt # 修改文件的 modify time
# stat 1.txt
File: '1.txt'
Size: 540 Blocks: 8 IO Block: 4096 regular file
Device: fc00h/64512d Inode: 132637 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-05-25 18:52:24.794779505 +0800
Modify: 2019-05-25 18:52:55.162298943 +0800
Change: 2019-05-25 18:52:55.162298943 +0800
Birth: -