是否可以使用标准 Linux 命令清除保留其时间戳的文件?例如:
echo ""> 文件名
将文本文件转换为空文件,这对我来说没问题。但我需要保持时间戳不变。
最佳答案
您可以使用触摸执行以下操作:
#!/bin/sh
TMPFILE=`mktemp`
#save the timestamp
touch -r file-name $TMPFILE
> file_name
#restore the timestamp after truncation
touch -r $TMPFILE file-name
rm $TMPFILE
关于linux - 清除文件而不更改其时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2920301/