RadarURL
Skip to content
조회 수 1371 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

touch

touch는 파일의 날짜시간정보를 변경하는 명령어이다.
즉 아무런 옵션이 없다면 파일의 최근에 사용한 시간과 최근에 변경된 시간을 서버의 현재시간으로 변경한다.
만약 지정된 명령어가 존재하지 않는다면 파일의 크기가 0인 빈 파일을 생성한다.

-t라는 옵션을 사용하면 서버의 현재시간이 아닌 지정된 시간으로 파일의 날짜시간정보를 변경한다.


명령어 사용형식

touch [-acfm] [-r file] [-t MMDDhhmm[[CC]YY][.ss]] [-d time]
[--time={atime,access,use,mtime,modify}] [--date=time] [--reference=file] [--no-create]
[--help] [--version] file...


사용예 #1

먼저 첫번째 예로서 아무런 옵션없이 파일이름만 지정하면 서버의 현재시간을 가진 비어있는 파일을 생성한다.

[root@host1 commmand]# touch file1
[root@host1 commmand]# ls -l
합계 0
-rw-r--r-- 1 root root 0 9월 10 13:05 file1
[root@host1 commmand]#

위의 예에서 file1이라는 파일이 서버의 현재 날짜시간으로 크기가 0인 파일이 생성이 되었다.

그러나 -c 옵션을 사용한다면 존재하지 않은 파일일 경우에는 파일을 생성하지 않는다.

[root@host1 commmand]# ls -l
합계 0
-rw-r--r-- 1 root root 0 9월 10 13:05 file1
[root@host1 commmand]#
[root@host1 commmand]# touch -c file2
[root@host1 commmand]#
[root@host1 commmand]# ls -l
합계 0
-rw-r--r-- 1 root root 0 9월 10 13:05 file1
[root@host1 commmand]#

위와 같이 -c옵션을 사용하였을 경우에는 지정된 파일(file2)가 존재하지 않는다면 새로 생성하지 않는다.


사용예 #2

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

[root@host1 commmand]# ls -l
합계 0
-rw-r--r-- 1 root root 0 9월 10 13:05 file1
[root@host1 commmand]#
[root@host1 commmand]# touch -t 09100111 file1
[root@host1 commmand]#
[root@host1 commmand]# ls -l
합계 0
-rw-r--r-- 1 root root 0 9월 10 01:11 file1
[root@host1 commmand]#

file1이라는 파일의 시간정보는 처음 생성되었던 정보인 "9월 10일 13시 5분"이였다.
그런데 "touch -t 09100111 file1"라는 명령어로 시간정보를 "9월 10일 01시 11분"으로 변경하였다.
위와 같이 -t옵션을 사용하여 특정한 날짜시간으로 파일의 정보를 변경할때에는 "MMDDhhmm[[CC]YY][.ss]"의 형식을 사용한다.


다음은 현재 날짜보다 이전날짜로 file1의 날짜를 변경하였을때의 예이다.

[root@host1 commmand]# touch -t 03050111 file1
[root@host1 commmand]# ls -l
합계 0
-rw-r--r-- 1 root root 0 3월 5 2003 file1
[root@host1 commmand]#

file1의 날짜시간정보를 "3월5일 01시 11분"으로 변경한 것이다.

만약 아무런 이유없이 특정파일(특히 관리자용 명령어)의 시간정보가 변경이 되었다면 해킹을 의심해 보아야한다.
따라서 서버관리자는 파일의 시간정보및 퍼미션정보등이 변경되었는가를 주기적으로 점검하여 해야한다.


사용예 #3

이번에는 특정파일의 날짜시간정보를 이용하여 지정된 파일의 날짜시간정보를 변경하는 예이다.

[root@host1 commmand]# ls -l
합계 0
-rw-r--r-- 1 root root 0 3월 5 2003 file1
-rw-r--r-- 1 root root 0 9월 10 13:05 file2
[root@host1 commmand]#
[root@host1 commmand]# touch -r file1 file2
[root@host1 commmand]# ls -l
합계 0
-rw-r--r-- 1 root root 0 3월 5 2003 file1
-rw-r--r-- 1 root root 0 3월 5 2003 file2
[root@host1 commmand]#

위에서 -r 옵션을 사용하여 file2의 날짜시간정보를 file1과 동일하게 변경하였다.

저작권 : 수퍼유저코리아 (www.superuser.co.kr), 무단 재배포및 복사를 금합니다

출처 : https://www.linux.co.kr/home/lecture/index.php?cateNo=&secNo=&theNo=&leccode=241

?

List of Articles
번호 제목 글쓴이 날짜 조회 수
162 AIX - tar,gzip 명령어 (한번에 압축하기) - Linux참고 JAESOO 2016.02.02 636
161 AIX Admin Study 교육 자료 JAESOO 2016.05.11 547
160 AIX 서버 기초 JAESOO 2016.05.11 560
159 AIX 시스템상의 core, SMT(Simultaneous Multi Threading) 수 확인하기 JAESOO 2016.05.12 604
158 AIX 자주 쓰이는 관리 명령 모음 JAESOO 2016.05.12 554
157 AIX에서 논리적 볼륨 크기 확장 JAESOO 2016.01.28 528
156 Apache HTTP Server, Rewrite가 안되는 경우 JAESOO 2014.05.26 930
155 Apache 파일시스템 권한 설정 JAESOO 2014.05.26 1004
154 Apache/FastCGI JaeSoo 2013.03.08 5915
153 CC 및 GCC 컴파일러 설치와 환경 설정 처누 2004.06.09 16696
152 CentOS - samba 자동실행 JAESOO 2014.05.26 1525
151 CentOS 5.0에 net-snmpd 설치 JAESOO 2014.12.26 782
150 CentOS 5.2 + Xmanager 설정 방법 JAESOO 2014.05.26 1226
149 Centos GeoIP 설치 JAESOO 2014.12.21 643
148 CentOS Network 설정 JAESOO 2014.05.26 1019
147 CentOS nmon 설치하기 JAESOO 2014.05.29 1701
146 CentOS Samba Server 설정 JAESOO 2014.05.26 1283
145 CentOS samba 공유 폴더 생성하기 JAESOO 2014.05.26 1048
144 CentOS Samba 설치 및 설정 JAESOO 2014.05.26 1291
143 CentOS X Window + Gnome Desktop 설치 JAESOO 2014.05.26 1297
Board Pagination Prev 1 2 3 4 5 6 7 8 9 Next
/ 9

PageViews   Today : 5020 Yesterday : 5037 Total : 21961072  /  Counter Status   Today : 4876 Yesterday : 4602 Total : 1187599

Edited by JAESOO

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소