touch命令詳解


一、用法

touch命令主要有兩個功能:

  • 將已存在文件的時間更改為當前系統時間
  • 創建一個空的文件

常見參數詳解:

-a  change only the access time

-c, --no-create
       do not create any files

-d, --date=STRING
       parse STRING and use it instead of current time

-f     (ignored)

-h, --no-dereference
       affect  each symbolic link instead of any referenced file (useful only
       on systems that can change the timestamps of a symlink)

-m     change only the modification time

-r, --reference=FILE
       use this file's times instead of current time

-t STAMP
      use [[CC]YY]MMDDhhmm[.ss] instead of current time

--time=WORD
      change the specified time: WORD is access, atime, or  use:  equivalent
      to -a WORD is modify or mtime: equivalent to -m

二、實戰

#創建一個不存在的空文件,如果存在無影響
[root@localhost project]# touch t1.txt

# 改變文件的時間戳
[root@localhost project]# touch -t 202010091130 t1.txt 
[root@localhost project]# ll
-rw-r--r--. 1 root root 4 Oct  9 11:30 t1.txt

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM