ANALYSIS
Linux 每日一篇 - 87 - touch
Linux 时间戳修改神器!掌握 touch 命令,轻松修改文件时间,创建空文件,管理文件状态!
touch 命令是什么?
touch 命令用于修改文件的访问时间和修改时间戳,如果文件不存在则创建空文件,是文件时间管理的基本工具。
基本用法
PRTCL // PLAINTEXT
# 创建空文件或更新时间戳touch filename
# 更新多个文件的时间戳touch file1 file2 file3
# 设置特定时间戳touch -t 202601231200 filename
# 设置特定日期时间touch -d "2026-01-23 12:00:00" filename
# 复制时间戳从另一个文件touch -r reference_file target_file
# 只更新访问时间touch -a filename
# 只更新修改时间touch -m filename
# 不创建不存在的文件touch -c filename实用技巧
PRTCL // PLAINTEXT
# 创建多个空文件touch file1.txt file2.txt file3.txt
# 更新文件到当前时间touch existing_file.txt
# 创建带特定时间戳的文件touch -d "yesterday" yesterday_file.txt
# 复制文件的时间戳touch -r source.txt target.txt
# 设置文件为特定时间touch -t 12312359 desired_time_file.txt # 12 月 31 日 23:59
# 检查 touch 后的效果touch testfile && stat testfile
# 批量更新文件时间touch *.log
# 在脚本中使用 touch 作为标记touch /tmp/script_running.flag常用场景
PRTCL // PLAINTEXT
# 创建临时文件touch /tmp/temp_file.txt
# 更新 makefile 依赖时间(强制重新编译)touch source.c
# 创建日志文件touch /var/log/myapp.log
# 设置文件时间用于测试touch -d "2026-06-15" test_file.txt
# 复制文件时间戳touch -r original.conf backup.conf
# 更新配置文件时间戳以触发服务重启touch /etc/myapp/config
# 创建多个空文件用于占位touch {1..10}.txt
# 在脚本中创建锁文件touch /tmp/myscript.lock# 脚本结束时删除锁文件rm /tmp/myscript.lock抖音文案
🎯 Linuxtouch 命令!
✅ 基本用法:touch ✅ 常用参数:touch -option ✅ 实用技巧:touch —help
每天一个 Linux 命令,30 天变身 Linux 高手!
#Linux 入门 #文件命令 #程序员必备 #技术分享
关于我
全平台同名”汪多多是只猫”,专注分享实用技术教程,让你的 IT 学习之路更轻松!
关注我,每天一个 Linux 命令,轻松入门 Linux 系统!
R P
Rhine Lab Pioneer Division
Auth_Verified: 2026.04.08
Auth_Verified: 2026.04.08
