touch 创建文件/更改文件的时间戳

  • touch 命令的主要作用是创建文件。为了能看到效果,本案例搭配 ls 命令演示。
    本案例是在当前路径下创建一个叫 123456.txt的文件:

    root@localhost ~]# ls
    myfile1.txt  myfile2.txt
    root@localhost ~]# touch 123456.txt
    root@localhost ~]# ls
    myfile1.txt  myfile2.txt   123456.txt
  • touch 命令的另一个作用是更改文件的时间戳。
    当touch 命令用作更改时间戳时,表示对应文件在当前目录下已存在,那么它不会被重新创建,而只会更改该文件的时间。
    为了更好地看到效果,本案例搭配 ll 命令演示。请注意文件的时间。

    root@localhost ~]# ll myfile1.txt
    -rw-r--r-- 1 root root 4 Jul 19 16:43 myfile1.txt
    root@localhost ~]# touch myfile1.txt
    root@localhost ~]# ll myfile1.txt
    -rw-r--r-- 1 root root 4 Jul 19 18:00 myfile1.txt
点赞

发表评论