zoukankan      html  css  js  c++  java
  • Linux命令(4):touch

    功能说明:

           touch命令参数可创建新文件以及更改文档或目录的日期时间,包括存取时间和更改时间。 

    命令格式:

            touch [选项]... 文件...

    命令参数:   

    -a   或--time=atime或--time=access或--time=use  只更改存取时间。

    -c   或--no-create  不建立任何文档。

    -d  使用指定的日期时间,而非现在的时间。

    -f  此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题。

    -m   或--time=mtime或--time=modify  只更改变动时间。

    -r  把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同。

    -t  使用指定的日期时间,而非现在的时间。

    命令案例:

    案例1、创建一个新文件

    [root@oldboy miao]# touch a.txt b.log
    [root@oldboy miao]# ll
    total 0
    -rw-r--r-- 1 root root 0 Aug 7 17:01 a.txt
    -rw-r--r-- 1 root root 0 Aug 7 17:01 b.log
    [root@oldboy miao]#

    案例2、更新a.txt的时间和b.log时间戳相同

    [root@oldboy miao]# ll
    total 0
    -rw-r--r-- 1 root root 0 Aug 7 17:06 a.log
    -rw-r--r-- 1 root root 0 Aug 7 17:01 a.txt
    -rw-r--r-- 1 root root 0 Aug 7 17:01 b.log
    [root@oldboy miao]# touch -r a.txt a.log
    [root@oldboy miao]# ll
    total 0
    -rw-r--r-- 1 root root 0 Aug 7 17:01 a.log
    -rw-r--r-- 1 root root 0 Aug 7 17:01 a.txt
    -rw-r--r-- 1 root root 0 Aug 7 17:01 b.log
    [root@oldboy miao]#

    案例3、设定文件的时间戳

    [root@oldboy miao]# touch -t 201408010000.00 a.log
    [root@oldboy miao]# ll
    total 0
    -rw-r--r-- 1 root root 0 Aug 1 00:00 a.log
    -rw-r--r-- 1 root root 0 Aug 7 17:01 a.txt
    -rw-r--r-- 1 root root 0 Aug 7 17:01 b.log
    [root@oldboy miao]#

    说明:此处的 time规定为如下形式的十进制数:       [[CC]YY]MMDDhhmm[.SS]     由于系统的限制,早于1970年1月1日的时间是错误的。

     

     

  • 相关阅读:
    仿佛看到了曾经在电子厂的自己
    TP5 condition 多个条件如何写
    电子数据时代我该如何保存我的数据?
    Shell脚本查询磁盘数量
    缺少维生素?
    html5的页面在IOS中,按钮 变成圆角怎么办?
    生物信息数据分析准则
    用variant的数据来推导基因表达 | Imputation of Expression Using PrediXcan
    Rare-Variant Association Analysis | 罕见变异的关联分析
    英语语法
  • 原文地址:https://www.cnblogs.com/miaokm/p/3897705.html
Copyright © 2011-2022 走看看