2

我需要递归目录树并将所有文件的时间戳的 YEAR ONLY 部分更新为某一年。我不知道如何通过触摸来做到这一点。我不能使用 touch -A 因为目标文件有很多不同的年份,所以相对调整已经结束。

我只是想将所有年份更新到 2013 年,无论它们目前是什么,但需要保持其余时间戳不变。这可能吗?

任何帮助表示赞赏。谢谢,史蒂夫。

4

1 回答 1

0
#!/bin/sh

#This is to ensure that the output of all the commands will be in english
export LANG=C

#Gets the modification date from the file, you can change it to get any other timestamp instead.
MODDATE=$(stat $1 | fgrep Modify | cut -d" " -f2)

YEAR=2013

#Sets month and day as the old date
MONTH=$(echo $MODDATE | cut -d- -f2)
DAY=$(echo $MODDATE | cut -d- -f3)

NEWDATE=$YEAR-$MONTH-$DAY

#Sets the new date
touch -d $NEWDATE $1
于 2013-05-18T14:04:02.077 回答