zoukankan      html  css  js  c++  java
  • 每天一个linux命令(9):touch

    1、命令简介

    touch命令将每个文件的访问时间和修改时间改为当前时间。

    2、用法

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

    3、选项

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

    4、实例

    实例1:在当前目录下建立一个空文件a.log
    [root@oracledb dir1]# touch a.log
    [root@oracledb dir1]# ll
    总用量 0
    -rw-r--r-- 1 root root 0 4月  16 21:06 a.log
    实例2:更新a.log的修改时间为当前时间
    [root@oracledb dir1]# ll
    总用量 0
    -rw-r--r-- 1 root root 0 4月  16 21:06 a.log
    [root@oracledb dir1]# touch a.log 
    [root@oracledb dir1]# ll
    总用量 0
    -rw-r--r-- 1 root root 0 4月  16 21:08 a.log
    实例3:更新log1.log的时间和log2.log时间戳相同
    [root@oracledb dir1]# ll
    总用量 0
    -rw-r--r-- 1 root root 0 4月  16 21:08 a.log
    -rw-r--r-- 1 root root 0 4月  16 21:12 b.log
    [root@oracledb dir1]# touch -r a.log   b.log 
    [root@oracledb dir1]# ll
    总用量 0
    -rw-r--r-- 1 root root 0 4月  16 21:08 a.log
    -rw-r--r-- 1 root root 0 4月  16 21:08 b.log
    实例4:设定文件的时间戳
    [root@oracledb dir1]# ll
    总用量 0
    -rw-r--r-- 1 root root 0 4月  16 21:08 a.log
    [root@oracledb dir1]# touch -t 201601011200.50 log.log
    [root@oracledb dir1]# ll
    总用量 0
    -rw-r--r-- 1 root root 0 4月  16 21:08 a.log
    -rw-r--r-- 1 root root 0 1月   1 12:00 log.log
     
  • 相关阅读:
    Gym 100801D Distribution in Metagonia (数学思维题)
    Gym 100801E Easy Arithmetic (思维题)
    GNOME编辑器--gedit 构建基本脚本
    linux默认编辑器 sublime
    su和su-命令的本质区别
    #ifdef #ifndef使用
    linux 安装软件程序
    linux命令行与shell脚本编程大全---更多bash shell命令
    预处理语句--#define、#error和#warning
    FW开发代码规范---小任性(2)
  • 原文地址:https://www.cnblogs.com/xqzt/p/5399407.html
Copyright © 2011-2022 走看看