강좌
클라우드/리눅스에 관한 강좌입니다.
리눅스 분류

파일의 날짜시간정보를 변경하는 touch실무3편: 파일의 날짜정보를 마음대로 변경할 수 있는 touch의 마술

작성자 정보

  • 관리자 작성
  • 작성일

컨텐츠 정보

본문

파일의 날짜시간정보를 변경하는 touch실무3: 파일의 날짜정보를 마음대로 변경할 수 있는 touch의 마술

 

 

 

 

이번에는 touch를 이용하여 특정파일의 날짜시간정보를 우리가 원하는 시간값으로 마음껏 변경하는 예를 보도록하자. 앞서 설명하였듯이 touch는 특정파일의 날짜시간정보를 변경하는 목적으로 제작된 명령어이다.

 

 

 

  따라서 touch를 이용하여 특정파일을 여러분들이 원하는 시간값으로 변경할 수 있다.

 

 

 

 

 

이번 예를 이해하기 위해서는 다음 touch의 사용형식을 이해해야 한다.

 

 

 

 

 

사용형식   : touch -t [[CC]YY]MMDDhhmm 대상파일



 

위와 같이 touch를 이용하여 지정한 파일의 날짜시간값을 변경할 때에는 -t옵션을 사용해야하고 날짜시간의 지정형식은 위와 같이 "[[CC]YY]MMDDhhmm"의 형식을 사용한다.

 

 

 

 여기서 CCYY는 년도를 의미하고, MM은 월, DD는 일, hhmm은 시분을 각각 의미한다.

 

 

 

 

 

다음은 특정파일의 날짜시간을 지정된 날짜시간정보로 변경하는 예이다.

 

 

 

 

 

[root@RockyLinux01 ~]# ls -l testfile

-rwS------ 1 root root 0  5  2 17:23 testfile

[root@RockyLinux01 ~]#

[root@RockyLinux01 ~]# touch -t 202306200101 testfile

[root@RockyLinux01 ~]#

[root@RockyLinux01 ~]# ls -l testfile

-rwS------ 1 root root 0  6 20 01:01 testfile

[root@RockyLinux01 ~]#

 

위의 testfile이라는 파일의 날짜정보는 2009 12 26일로 되어있다.

 

 

 

 그런데 touch명령어를 이용하여 202306 20일로 변경하였다.

 

 

 

 변경 후에 ls로 날짜시간을 확인해 보면 알 수 있다.

 

 

 

 

 

그리고 다음은 testfile파일날짜시간 정보를 2012 09 15로 변경하였다.

 

 

 

[root@RockyLinux01 ~]# ls -l testfile

-rwS------ 1 root root 0  6 20 01:01 testfile

[root@RockyLinux01 ~]#

[root@RockyLinux01 ~]# touch -t 202306230101 testfile

[root@RockyLinux01 ~]#

[root@RockyLinux01 ~]# ls -l testfile

-rwS------ 1 root root 0  6 23  2023 testfile

[root@RockyLinux01 ~]#

 

위의 예에서도 anacrontab파일의 날짜시간정보가 20230623일로 변경하였다.

 

 

 

 이와같이 우리가 원하는 어떤 날짜시간으로도 파일의 시간정보를 변경할 수 있음을 알 수 있다.

 

 

 

 

 

 



이번에는 지정한 파일의 날짜시간정보를 지정한 다른 파일의 날짜시간 정보와 동일하게 변경하는 예를 설명한 것이다.

 

 

 

 , touch명령어를 이용하면 특정파일의 시간정보와 동일하게 원하는 파일의 시간정보를 변경할 수 있다.

 

 

 

 , 특정파일의 날짜시간정보를 확인하고 지정한 파일의 시간정보를 변경하는 것이다.

 

 

 

 그리고 한번에 여러 개의 파일의 날짜시간을 변경할 수도 있다.

 

 

 

 

 

아래를 보면 testfile파일의 정보와 현재 디렉토리에 존재하는 파일들의 정보를 다음과 같이 확인하였다.

 

 

 

 

 

[root@RockyLinux01 ~]# ls -l testfile

-rwS------ 1 root root 0  6 23  2023 testfile

[root@RockyLinux01 ~]#

[root@RockyLinux01 ~]# ls -l typescript

-rw-r--r-- 1 root root 6637  5 16 15:44 typescript

[root@RockyLinux01 ~]#

 

 

 

그리고 다음은 testfile파일의 날짜시간정보와 동일하게 현재 디렉토리에 존재하는 typescript파일의 날짜시간정보를 변경하였다.

 

 

 

 

 

[root@RockyLinux01 ~]# touch -r testfile typescript

[root@RockyLinux01 ~]#

[root@RockyLinux01 ~]# ls -l typescript

-rw-r--r-- 1 root root 6637  6 23  2023 typescript

[root@RockyLinux01 ~]#

 

그리고 다음은 현재 디렉토리에 존재하는 모든 파일의 날짜시간정보를 testfile파일의 날짜시간정보와 동일하게 변경한 것이다.

 

 

 

 다음 예를 보자.

 

[root@RockyLinux01 test]# ls -l

합계 168

-rwxr-xr-x 1 root root 25800  6  8 17:54 a.out

-rw-r--r-- 1 root root  2204  6 13 16:08 aaa.txt

-rw-r--r-- 1 root root  2107  6 13 14:15 announce.txt

-rwxr-xr-x 1 root root   200  6  8 15:59 apachemon.sh

-rwxr-xr-x 1 root root   293  6  5 15:27 case01.sh

-rwxr-xr-x 1 root root    72  6  5 15:34 for01.sh

-rwxr-xr-x 1 root root    86  6  5 15:37 for02.sh

-rwxr-xr-x 1 root root   148  6  5 15:46 if001.sh

-rwxr-xr-x 1 root root   148  6  5 15:54 if002.sh

-rwxr-xr-x 1 root root   188  6  5 16:00 if003.sh

-rwxr-xr-x 1 root root   543  6  5 16:04 if004.sh

-rwxr-xr-x 1 root root   228  6  8 15:52 logger.sh

-rw-r--r-- 1 root root    93  6  8 17:59 main.c

-rw-r--r-- 1 root root  1360  6  8 17:59 main.o

-rw------- 1 root root     0  6  8 16:00 nohup.out

-rw-r--r-- 1 root root    67  6  8 17:59 print.c

-rw-r--r-- 1 root root  1512  6  8 17:59 print.o

-rw-r--r-- 1 root root   986  6  8 14:13 proch.sh

-rwxr-xr-x 1 root root    30  6  5 11:46 read01.sh

-rwxr-xr-x 1 root root    34  6  5 11:48 read02.sh

-rwxr-xr-x 1 root root    78  6  5 11:50 read03.sh

-rwxr-xr-x 1 root root    88  6  5 14:58 read04.sh

-rwxr-xr-x 1 root root   113  6  5 15:02 read05.sh

-r--r--r-- 1 root root    95  6 13 14:15 robots.txt

-rwxr-xr-x 1 root root   296  6  8 13:14 select01.sh

-rwxr-xr-x 1 root root 25800  6  8 17:58 superuser

-rw-r--r-- 1 root root   101  6  8 17:52 superuser.c

-rw-r--r-- 1 root root  1512  6  8 17:57 superuser.o

-rw-r--r-- 1 root root     0  6 22 14:06 testfile

-rwxr-xr-x 1 root root    93  6  5 16:12 until01.sh

-rwxr-xr-x 1 root root    93  6  5 16:15 while01.sh

-rwxr-xr-x 1 root root   191  6  8 12:46 while02.sh

[root@RockyLinux01 test]#

[root@RockyLinux01 test]# touch -r testfile *

[root@RockyLinux01 test]#

[root@RockyLinux01 test]# ls -l

합계 168

-rwxr-xr-x 1 root root 25800  6 22 14:06 a.out

-rw-r--r-- 1 root root  2204  6 22 14:06 aaa.txt

-rw-r--r-- 1 root root  2107  6 22 14:06 announce.txt

-rwxr-xr-x 1 root root   200  6 22 14:06 apachemon.sh

-rwxr-xr-x 1 root root   293  6 22 14:06 case01.sh

-rwxr-xr-x 1 root root    72  6 22 14:06 for01.sh

-rwxr-xr-x 1 root root    86  6 22 14:06 for02.sh

-rwxr-xr-x 1 root root   148  6 22 14:06 if001.sh

-rwxr-xr-x 1 root root   148  6 22 14:06 if002.sh

-rwxr-xr-x 1 root root   188  6 22 14:06 if003.sh

-rwxr-xr-x 1 root root   543  6 22 14:06 if004.sh

-rwxr-xr-x 1 root root   228  6 22 14:06 logger.sh

-rw-r--r-- 1 root root    93  6 22 14:06 main.c

-rw-r--r-- 1 root root  1360  6 22 14:06 main.o

-rw------- 1 root root     0  6 22 14:06 nohup.out

-rw-r--r-- 1 root root    67  6 22 14:06 print.c

-rw-r--r-- 1 root root  1512  6 22 14:06 print.o

-rw-r--r-- 1 root root   986  6 22 14:06 proch.sh

-rwxr-xr-x 1 root root    30  6 22 14:06 read01.sh

-rwxr-xr-x 1 root root    34  6 22 14:06 read02.sh

-rwxr-xr-x 1 root root    78  6 22 14:06 read03.sh

-rwxr-xr-x 1 root root    88  6 22 14:06 read04.sh

-rwxr-xr-x 1 root root   113  6 22 14:06 read05.sh

-r--r--r-- 1 root root    95  6 22 14:06 robots.txt

-rwxr-xr-x 1 root root   296  6 22 14:06 select01.sh

-rwxr-xr-x 1 root root 25800  6 22 14:06 superuser

-rw-r--r-- 1 root root   101  6 22 14:06 superuser.c

-rw-r--r-- 1 root root  1512  6 22 14:06 superuser.o

-rw-r--r-- 1 root root     0  6 22 14:06 testfile

-rwxr-xr-x 1 root root    93  6 22 14:06 until01.sh

-rwxr-xr-x 1 root root    93  6 22 14:06 while01.sh

-rwxr-xr-x 1 root root   191  6 22 14:06 while02.sh

[root@RockyLinux01 test]#

 

이제 우리는 touch를 이용하여 어떤 파일이든 우리가 원하는 모든 날짜시간 정보로 변경할 수 있다는 것을 알았다.

 

 

 

  touch를 보다 원활하게 사용할 수 있게 된다면 시스템관리의 깊이가 보다 깊어진다.

 

 

 

 , 파일의 날짜시간의 종류가 하나만 있다는 것이 아니라는 것도 알게 되고, 날짜시간 정보를 원하는 시간 값으로 얼마든지 변경할 수 있다는 것도 알게 된다.

 

 

 

 그리고 또한 우리가 ls로 확인하는 날짜시간정보에 대한 신뢰도에 대해서도 의문을 가지게 된다.

 

 

 

 

 

주의할 것은 아무런 이유없이 특정파일(특히 관리자용 명령어)의 시간정보가 변경되었다면 해킹을 의심해 보아야 한다는 점이다.

 

 

 

 따라서 시스템관리자는 파일의 시간정보 및 퍼미션정보등이 변경되었는가를 주기적으로 점검해야 한다.

 

 

 

 

 

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,038 명
  • 현재 강좌수 :  35,818 개
  • 현재 접속자 :  126 명