linux 命令:touch 详解 您所在的位置:网站首页 Linux命令touch linux 命令:touch 详解

linux 命令:touch 详解

2024-07-10 14:20| 来源: 网络整理| 查看: 265

用法:touch [OPTION]... FILE... 更新一个文件的访问时间(atime)和修改时间(mtime)为当前时间。 如果不使用 -c 或 -h ,创建一个空文件。 FILE参数字符串 - 是经过特殊处理的,并使touch更改与标准输出关联的文件的时间。 -a 只更改访问时间(atime) -c, --no-create 不创建任何文件 -d, --date=字符串 使用指定字符串表示时间而非当前时间 -f (忽略) -h, --no-dereference 会影响符号链接本身,而非符号链接所指示的目的地 (当系统支持更改符号链接的所有者时,此选项才有用) -m 只更改修改时间(mtime) -r, --reference=FILE 使用FILE的时间参数,而不是当前时间 -t STAMP 使用 [[CC]YY]MMDDhhmm[.ss] 而不是当前时间 --time=WORD 改变具体时间: WORD 是 access, atime, 相当于使用 -a WORD 是 modify, mtime, 相当于使用 -m --help 显示此帮助信息并退出 --version 显示版本信息并退出 请注意,-d 和 -t 选项可接受不同的时间/日期格式。

使用示例:

1. 修改文件的atime, mtime:

[root@server dir]# ll file1 -rw-r--r-- 1 root root 0 11月 28 15:12 file1 [root@server dir]# touch file1 [root@server dir]# ll file1 -rw-r--r-- 1 root root 0 11月 29 14:19 file1 [root@server dir]# stat file1 文件:"file1" 大小:0 块:0 IO 块:4096 普通空文件 设备:fd01h/64769d Inode:1050106 硬链接:1 权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root) 最近访问:2021-11-29 14:19:22.248921719 +0800 最近更改:2021-11-29 14:19:22.248921719 +0800 最近改动:2021-11-29 14:19:22.248921719 +0800 创建时间:-

可以看到,file1在执行touch之后,atime和mtime都发生了变化。

2. 创建新的空文件:

[root@server dir]# ll 总用量 12 drwxr-xr-x 2 root root 4096 11月 28 15:12 dir1 lrwxrwxrwx 1 root root 4 11月 28 15:13 dir2 -> dir1 -rw-r--r-- 1 root root 0 11月 29 14:19 file1 -rw-r--r-- 1 root root 4 11月 28 16:41 file2 -rw-r--r-- 1 root root 0 11月 28 15:12 file3 -rw-r--r-- 1 root root 164 11月 28 16:41 file.zip [root@server dir]# touch file4 [root@server dir]# ll 总用量 12 drwxr-xr-x 2 root root 4096 11月 28 15:12 dir1 lrwxrwxrwx 1 root root 4 11月 28 15:13 dir2 -> dir1 -rw-r--r-- 1 root root 0 11月 29 14:19 file1 -rw-r--r-- 1 root root 4 11月 28 16:41 file2 -rw-r--r-- 1 root root 0 11月 28 15:12 file3 -rw-r--r-- 1 root root 0 11月 29 14:41 file4 -rw-r--r-- 1 root root 164 11月 28 16:41 file.zip [root@server dir]# file file4 file4: empty

可以看到,file4被成功创建,并且是个空文件。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有