linux一步一脚印---touch

1 命令功能(简要说明):

    touch命令主要存在两个用法(1)将文件的访问时间和修改时间改成当前时间;(2)不存在的文件将会被创建为空文件,除非使用-c或-h选项;

2 命令语法:

    touch 【选项】 文件...     #注:【】中的内容为非必选项

3 命令选项(只做常用命令参数讲述):

  使用帮助命令:man touch 或 touch -help

-a 只更改访问时间
-c, --no-create 不创建任何文件
-d, --date=字符串 使用指定字符串表示时间而非当前时间
-f (忽略)
-h, --no-dereference 会影响符号链接本身,而非符号链接所指示的目的地(当系统支持更改符号链接的所有者时,此选项才有用)
-m 只更改修改时间
-r, --reference=文件 使用指定文件的时间属性而非当前时间
-t STAMP 使用[[CC]YY]MMDDhhmm[.ss] 格式的时间而非当前时间

CC 指定年份的前两位数字。YY 指定年份的后两位数字。MM 指定一年的哪一月, 1-12。
DD 指定一年的哪一天, 1-31。hh 指定一天中的哪一个小时, 0-23。mm 指定一小时的哪一分钟, 0-59。

--time=WORD 使用WORD 指定的时间:access、atime、use 都等于-a
选项的效果,而modify、mtime 等于-m 选项的效果
--help 显示此帮助信息并退出
--version 显示版本信息并退出

4 使用范例:

  (1)是用touch命令建立空文件,注意使用touch创建空文件的时候,file命令是无法判断该文件的类型,当文件不存在时则创建空文件;

[root@localhost command_test]# touch test.txt
[root@localhost command_test]# file test.txt
test.txt: empty
[root@localhost command_test]# mkdir test_dir
[root@localhost command_test]# file test_dir/
test_dir/: directory
[root@localhost command_test]# 

 

 

  (2)修改文件访问时间(注意下列标黄部分对时间的更改)

[root@localhost command_test]# ls
1.txt  2.txt
[root@localhost command_test]# stat 1.txt  #stat命令用于查看文件的信息
  File: "1.txt"
  Size: 8               Blocks: 8          IO Block: 4096   普通文件
Device: 802h/2050d      Inode: 26          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-08-29 13:01:13.972616361 +0800
Modify: 2018-08-29 13:01:00.068796143 +0800
Change: 2018-08-29 13:01:00.068796143 +0800
[root@localhost command_test]# touch -t 200011120112.08 1.txt
[root@localhost command_test]# stat 1.txt
  File: "1.txt"
  Size: 8               Blocks: 8          IO Block: 4096   普通文件
Device: 802h/2050d      Inode: 26          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2000-11-12 01:12:08.000000000 +0800
Modify: 2000-11-12 01:12:08.000000000 +0800
Change: 2018-08-29 21:40:52.603679512 +0800
[root@localhost command_test]# 

 

   (3)touch -d 参数使用用例

#如果没有指定日期,默认为系统日期
[root@localhost command_test]# touch -d 18:03 file 
[root@localhost command_test]# touch -d "18:03" file 
[root@localhost command_test]# touch -d "6:03pm" file
#如果没有指定时间,默认为 00:00:00
[root@localhost command_test]# touch -d 20180506 file 
[root@localhost command_test]# touch -d "05/06/2018" file 
[root@localhost command_test]# touch -d "20180506" file
[root@localhost command_test]# touch -d "6:03pm 05/06/2018" file 
[root@localhost command_test]# touch -d "20180506 18:03" file 
[root@localhost command_test]# touch -d "20180506 18:03:00" file

 

   (4)touch -t 参数使用用例

 

#这里选择了-t参数中的  YYMMDDhhmm 对号入座既可
[root@localhost command_test]# touch -t 5502021314 file

 

还有其他功能就不一一列举了,这里附上一张图片

 

 

  

 

转载于:https://www.cnblogs.com/king-of-purple/p/9550991.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值