zoukankan      html  css  js  c++  java
  • 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

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

      

  • 相关阅读:
    勉励自己
    python2+selenium爬取笔趣读小说
    ubuntu下配置host的方法
    如何解决执行Python文件时出现but no encoding declared
    如何解决Python打印汉字时报错UnicodeEncodeError: 'ascii' codec can't encode characters in position 9-12: ordinal not in range(128)
    ubuntu系统下selenium打开火狐浏览器提示'Unable to find a matching set of capabilities.和Message: connection refused
    ubuntu系统下selenium打开火狐浏览器提示'geckodriver' executable needs to be in PATH.解决方法
    Ubuntu系统开root如何解决su:认证失败?
    主机与虚拟机Oracle VM VirtualBox不能复制粘贴的解决办法
    如何解决ubuntu安装selenium时出现错误:Cannot fetch index base URL http://pypi.python.org/simple/
  • 原文地址:https://www.cnblogs.com/king-of-purple/p/9550991.html
Copyright © 2011-2022 走看看