업데이트된 답변

업데이트된 답변

이것은 쉽게 연구할 수 있는 질문인 것 같습니다. 그렇지 않습니다. 나는 우연히 우연히 만난 Ubuntu Stack Exchange 사이트에서 다음과 같이 적극 권장되는 게시물을 따르고 있습니다. 하지만 이 제안은 Red Hat Enterprise Linux ES 릴리스 4에서는 작동하지 않습니다. 예상한 대로 작동했지만 아래 설명처럼 실패했습니다.

이것이제안: 구체적으로 포스터에서 권장하는 사항은 다음과 같습니다.

대신 기존 수정 시간을 기준으로 파일을 수정하려면 다음을 수행해야 합니다.

touch -d "$(date -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

( @don_crissti info coreutils touch invocation감사합니다):

'-r 파일'

'--참조=파일'

 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

관련 정보