1. 基本语法及功能
2. 注意点说明
3. 常用选项及测试
3.1 不指定路径创建文件
/* 查看当前所在目录 */
[Mortal@VM-12-16-centos ~]$ pwd
/home/Mortal
[Mortal@VM-12-16-centos ~]$ cd StudyingOrder_Linux/
/* 创建测试目录 */
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ mkdir test_touch
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ ls
test_touch test.txt
/* 不指定路径创建文件 */
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ touch test1.txt
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ ls
test1.txt test_touch test.txt
3.2 指定路径创建目录
/* 指定路径创建目录 */
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ touch test_touch/test2.txt
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ ls
test1.txt test2.txt test_touch test.txt
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ ls test_touch/
test2.txt
3.3 指定在其他路径下创建文件
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ ls /home/Mortal
StudyingOrder_Linux test1 test2 test3
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ touch /home/Mortal/test1/testtxt.txt
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ ls /home/Mortal/test1
testtxt.txt
4. 修改文件创建时间
4.1 基本操作测试
/* 查看上例中 StudyingOrder_Linux/test.txt 的创建/修改时间 */
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ ll test.txt
-rw-rw-r-- 1 Mortal Mortal 0 May 26 15:17 /home/Mortal/StudyingOrder_Linux/test.txt
/* test.txt 文件的创建时间为:May 26 15:17 */
/* 重新创建同名文件并查看创建/修改时间 */
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ touch test.txt
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ ll test.txt
-rw-rw-r-- 1 Mortal Mortal 0 May 26 16:44 /home/Mortal/StudyingOrder_Linux/test.txt
/* 新时间:May 26 16:44 */
4.2 重建式的修改,会影响文件中的内容吗?
/* 重建式的修改,会影响文件中的内容吗?不会 */
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ echo "hello" > text.txt /* 重定向方式像文件中写入信息 */
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ cat text.txt /* cat:查看指定文件中的内容! */
hello
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ touch text.txt
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ cat text.txt
hello
4.3 关于 [-a / -m] 可选选项修改存取/更改时间测试
(可能有点出入!)
/* stat + 文件:查看文件的操作时间 */
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ stat text.txt
File: ‘text.txt’
Size: 6 Blocks: 8 IO Block: 4096 regular file
Device: fd01h/64769d Inode: 657455 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Mortal) Gid: ( 1001/ Mortal)
Access: 2023-05-26 16:51:49.780719889 +0800 /* 显示时间点:存取 */
Modify: 2023-05-26 16:51:48.250722863 +0800 /* 显示时间点:更改 */
Change: 2023-05-26 16:51:48.250722863 +0800 /* 显示时间点:修改 */
Birth: -
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ touch -a text.txt
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ stat text.txt
File: ‘text.txt’
Size: 6 Blocks: 8 IO Block: 4096 regular file
Device: fd01h/64769d Inode: 657455 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Mortal) Gid: ( 1001/ Mortal)
Access: 2023-05-26 16:55:50.785251530 +0800 /* 显示时间点:存取(变动) */
Modify: 2023-05-26 16:51:48.250722863 +0800 /* 显示时间点:更改 */
Change: 2023-05-26 16:55:49.252254509 +0800 /* 显示时间点:修改(变动) */
Birth: -
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ touch -m text.txt
[Mortal@VM-12-16-centos StudyingOrder_Linux]$ stat text.txt
File: ‘text.txt’
Size: 6 Blocks: 8 IO Block: 4096 regular file
Device: fd01h/64769d Inode: 657455 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Mortal) Gid: ( 1001/ Mortal)
Access: 2023-05-26 16:56:04.788224316 +0800 /* 显示时间点:存取(变动) */
Modify: 2023-05-26 16:56:02.851228080 +0800 /* 显示时间点:更改 */
Change: 2023-05-26 16:56:02.851228080 +0800 /* 显示时间点:修改(变动) */
Birth: -