栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

linux 命令:touch 详解

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

linux 命令:touch 详解

用法: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被成功创建,并且是个空文件。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/618308.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号