文件名 将文本文件转换为空文件,这对我来说没问题。但我需要保持时间戳不变。 最佳答案 您可以使用触摸执行以下操作: -6ren">
gpt4 book ai didi

linux - 清除文件而不更改其时间戳

转载 作者:IT王子 更新时间:2023-10-29 00:56:52 26 4
gpt4 key购买 nike

是否可以使用标准 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com