ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • LINUX Touch 명령어를 통한 날짜 수정하는 방법
    System of Infra/Linux System 2024. 1. 2. 08:00
    반응형

    LINUX 로고이미지

    LINUX Touch 명령어를 통한 날짜 수정하는 방법

    [root@TESTSVR tmp]# touch datechagefile1
    [root@TESTSVR tmp]# touch datechagefile2
    [root@TESTSVR tmp]# touch datechagefile3
    ▶ touch 명령어를 통해서 파일 3개를 생성합니다.
    [root@TESTSVR tmp]# ls -al | grep -i date
    -rw-r--r-- 1 root root 0  8월  2 09:16 datechagefile1
    -rw-r--r-- 1 root root 0  8월  2 09:18 datechagefile2
    -rw-r--r-- 1 root root 0  8월  2 09:19 datechagefile3
    ▶ touch 명령어를 통해 생성된 파일의 날짜는 다음과 같습니다.
    datechagefile1: 08/02 09:16 datechagefile2: 08/02 09:18 datechagefile3: 08/02 09:19
    [root@TESTSVR tmp]# touch -c datechagefile1
    
    [root@TESTSVR tmp]# ls -al | grep -i date
    -rw-r--r-- 1 root root 0  8월  2 09:19 datechagefile1
    -rw-r--r-- 1 root root 0  8월  2 09:18 datechagefile2
    -rw-r--r-- 1 root root 0  8월  2 09:19 datechagefile3
    ▶ touch -c datechagefile1 명령어를 통해서 현재 날짜와 시간으로 파일이 저장됩니다.
    (08/02 09:16 -> 08/02 09:19 변경)
    [root@TESTSVR tmp]# touch -t 202307052315 datechagefile2
    
    [root@TESTSVR tmp]# ls -al | grep -i date
    -rw-r--r-- 1 root     root    0  8월  2 09:19 datechagefile1
    -rw-r--r-- 1 root     root    0  7월  5 23:15 datechagefile2
    -rw-r--r-- 1 root     root    0  8월  2 09:19 datechagefile3
    ▶ touch -t 202307052315 datechagefile2 명령어를 통해서 수동으로 날짜를 변경할 수 있습니다.
    (08/02 09:18 -> 07/05 23:15 변경)
    [root@TESTSVR tmp]# touch -r datechagefile2 datechagefile3
    
    [root@TESTSVR tmp]# ls -al | grep -i date
    -rw-r--r-- 1 root     root    0  8월  2 09:19 datechagefile1
    -rw-r--r-- 1 root     root    0  7월  5 23:15 datechagefile2
    -rw-r--r-- 1 root     root    0  7월  5 23:15 datechagefile3
    ▶ touch -r datechagefile2 datechagefile3 명령어를 통해서 datechagefile3 파일의 생성 날짜 및 시간을 datechagefile2와 동일하게 변경할 수 있습니다.
    [root@TESTSVR tmp]# touch -r datechagefile3 datechagefile1
    
    [root@TESTSVR tmp]# ls -al | grep -i date
    -rw-r--r-- 1 root root 0  7월  5 23:15 datechagefile3
    -rw-r--r-- 1 root root 0  7월  5 23:15 datechagefile2
    -rw-r--r-- 1 root root 0  7월  5 23:15 datechagefile1
    ▶ 마찬가지로 datechagefile1 파일 생성날짜와 시간을 datechagefile3 동일하게 변경할 수 있습니다.
    [변경 전 파일 생성 날짜] datechagefile1: 08/02 09:16 datechagefile2: 08/02 09:18 datechagefile3: 08/02 09:19
    [변경 후 파일 생성 날짜] datechagefile1: 07/05 23:15 datechagefile2: 07/05 23:15 datechagefile3: 07/05 23:15
    [root@TESTSVR tmp]# touch -c datechagefile1
    
    [root@TESTSVR tmp]# ls -al | grep -i date
    -rw-r--r-- 1 root root 0  7월  5 23:15 datechagefile3
    -rw-r--r-- 1 root root 0  7월  5 23:15 datechagefile2
    -rw-r--r-- 1 root root 0  8월  2 09:24 datechagefile1
    ▶ touch -c datechagefile1 명령어를 통해서 현재 날짜와 시간으로 파일을 변경할 수 있습니다.
    [root@TESTSVR tmp]# touch -r datechagefile1 datechagefile3; touch -r datechagefile1 dateachagefile2
    
    [root@TESTSVR tmp]# ls -al | grep -i date
    -rw-r--r-- 1 root root 0  8월  2 09:24 datechagefile3
    -rw-r--r-- 1 root root 0  8월  2 09:24 datechagefile2
    -rw-r--r-- 1 root root 0  8월  2 09:24 datechagefile1
    ▶ 옵션 -r을 통해서 datechagefile3, datachagefile2은 datachagefile1과 동일한 날짜로 변경하여 생성 날짜를 임의로 변경이 가능합니다.

     

    PS. 포스팅의 내용은 제 기준으로 작성한 것이기 때문에 참고해서 보시면 감사하겠습니다.

    포스팅 과정의 오류 및 오타 그리고 궁금한 점에 대해서는 댓글 남겨주세요.

    반응형

    댓글

Designed by Tistory.