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 に答える