심볼릭 링크의 타임스탬프 변경

심볼릭 링크의 타임스탬프 변경

일반 파일의 타임스탬프를 변경하는 방법을 알고 있습니다.

touch -t 201301291810 myfile.txt

심볼릭 링크를 사용하여 동일한 작업을 수행할 수 없습니다. 가능합니까?

릴리스: RHEL 5.8

답변1

스위치 추가 -h

touch -h -t 201301291810 myfile.txt

Mandatory arguments to long options are mandatory for short options too.
  -a                     change only the access time
  -c, --no-create        do not create any files
  -d, --date=STRING      parse STRING and use it instead of current time
  -f                     (ignored)
  -h, --no-dereference   affect each symbolic link instead of any referenced
                         file (useful only on systems that can change the
                         timestamps of a symlink)
  -m                     change only the modification time
  -r, --reference=FILE   use this file's times instead of current time
  -t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time

답변2

최신 버전이 필요할 수 있습니다 touch. 이것이 옵션이 아니고 C를 알고 있다면 다음을 사용하여 작은 프로그램을 직접 작성할 수 있습니다.황체 기능.

답변3

무차별 대입 크래킹 방법은 다음과 같습니다.

 0. delete the old symlink you wish to change     
 1. change the system date to whatever date you want the symlink to be
 2. remake the symlink
 3. return the system date to current.

답변4

이 함수를 사용하여 심볼릭 링크의 atime과 mtime을 변경할 수 있습니다 lutimes. 다음 프로그램은 MacOSX 및 Linux에서 작동하여 모든 파일을 심볼릭 링크에 두 번 복사합니다.

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>

int
main(int argc, char **argv)
{
    struct timeval times[2];
    struct stat info;
    int rc;

    if (argc != 3) {
        fprintf(stderr, "usage: %s source target\n", argv[0]);
        return 1;
    }
    rc = lstat(argv[1], &info);
    if (rc != 0) {
        fprintf(stderr, "error: cannot stat %s, %s\n", argv[1],
                strerror(errno));
        return 1;
    }

    times[0].tv_sec = info.st_atime;
    times[0].tv_usec = 0;
    times[1].tv_sec = info.st_mtime;
    times[1].tv_usec = 0;
    rc = lutimes(argv[2], times);
    if (rc != 0) {
        fprintf(stderr, "error: cannot set times on %s, %s\n", argv[2],
                strerror(errno));
        return 1;
    }

    return 0;
}

컴파일된 파일을 호출하는 경우 copytime이 명령을 사용하여 copytime file link링크가 링크와 동일한 atime 및 mtime을 갖도록 만들 수 있습니다 file. 다른 파일에서 시간을 복사하는 대신 명령줄에 지정된 시간을 사용하도록 프로그램을 수정하는 것은 그리 어렵지 않습니다.

관련 정보