• 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日的时间是错误的。

     

     

  • 相关阅读:
    Apache POI
    关于数据池连接技术
    CentOS下安装MySQL
    CentOS下安装JDK的三种方法
    Java大话设计模式
    vs2010安装svn插件
    IIS中如何建立FTP服务
    .net控件dropdownlist动态绑定数据 ----转
    在ASP.NET项目中使用CKEditor
    常用Java Web 服务器
  • 原文地址:https://www.cnblogs.com/miaokm/p/3897705.html
Copyright © 2020-2023  润新知