最後更新: 2022-11-03
介紹
修改/更新 mtime, atime
任意修改 mtime, atime
"touch" 除了可以更新檔案的建立(mtime)及存取(atime)時間外,
它更可以修改它們成任意時間
不過, 此功能只限 root 及 owner 才可以用到 !!
- -m # 只更新 mtime
- -a # 只更新 atime
- -t STAMP # 用這 format 的 value 去修改時間 [[CC]YY]MMDDhhmm[.ss]
- -c, --no-create # do not create any files
- -r file # use this file's times instead of current time
Example:
# 相當於 -m, -a
touch test.py
# 以 -t 設定(建立) log.txt 的 mtime & atime
touch -t 02230950 log.txt
stat log.txt
File: log.txt
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 812h/2066d Inode: 393048 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2024-02-23 09:50:00.000000000 +0800
Modify: 2024-02-23 09:50:00.000000000 +0800
Change: 2024-02-23 09:55:50.583359206 +0800
Birth: 2024-02-23 09:54:58.983358956 +0800
另見
# 當 log.txt 不存在時, 不會建立 log.txt
touch -c -t 02230950 log.txt