更新された回答

更新された回答

これは簡単に調査できる質問のように思えますが、そうではありません。私は、偶然見つけた Ubuntu Stack Exchange サイトで、非常に推奨されている次の投稿に従っています。しかし、この提案は Red Hat Enterprise Linux ES リリース 4 では機能しません。機能すると予想していましたが、以下に説明するように、機能しません。

これは提案: 具体的には、ポスターでは

代わりに、既存の変更時刻を基準にしてファイルを変更したい場合は、次のようにします。

touch -d "$(日付 -R -r ファイル名) - 2時間" ファイル名

これはRedhatでは機能しません。マイナス記号は無視され、入力したのと同じように時間が2日進みます。

touch -d "$(date -R -r filename) + 2 hours" filename

例えば:

$ ls -al test
-rw-r-----  1 sc1478 dev 5 Oct 27 12:59 test

$ touch -d "$(date -R -r test) - 8 days" test

$ ls -al test
-rw-r-----  1 sc1478 dev 5 Nov  4  2016 test

$ touch -d "$(date -R -r test) + 8 days" test

$ ls -al test 
-rw-r-----  1 sc1478 dev 5 Nov 12  2016 test

マイナス記号を使用してもプラス記号を使用しても、日付は前へ調整されます。

これはタッチの特定のバージョンのバグでしょうか?

現在のタイムスタンプを基準にしてファイルのタイムスタンプを調整する別の方法はありますか?

答え1

更新された回答

私はこの宝石に偶然出会った

touch -r filename -d '+8 days' filename

info coreutils touch invocation(ありがとう @don_crissti )より:

'-r ファイル'

'--reference=ファイル'

 Use the times of the reference FILE instead of the current time.
 If this option is combined with the '--date=TIME' ('-d TIME')
 option, the reference FILE's time is the origin for any relative
 TIMEs given, but is otherwise ignored.  For example, '-r foo -d
 '-5 seconds'' specifies a time stamp equal to five seconds before
 the corresponding time stamp for 'foo'.  If FILE is a symbolic
 link, the reference timestamp is taken from the target of the
 symlink, unless '-h' was also in effect.

変数を拡張したい場合は、次のように引数をソフト引用符で囲みます-d

DAYS=8
touch -r filename -d "+${DAYS} days" filename

サンプル:

$ ls -l foo.bar
-rw-r--r-- 1 usr usr 69414810 Nov 10  2016 foo.bar
$ TEST=100
$ touch -r foo.bar -d "+${TEST} days" foo.bar
$ ls -l foo.bar 
-rw-r--r-- 1 usr usr 69414810 Feb 24  2017 foo.bar

関連情報