Thursday, November 26, 2009

리눅스 - tar 압축 사용법

리눅스 - tar 압축 사용법

ruo912009-11-10 02:26:50주소복사
조회 351 스크랩 0
리눅스에서 tar 압축 명령어를 사용하는 방법입니다.

tar 압축하기
[root@ruo91 ~]# tar [옵션] [압축 될 파일명] [압축할 디렉토리 또는 파일]
[root@ruo91 ~]# tar cvf ruo91.tar /home/ruo91/public_html
cvf 옵션 추가

tar.gz 압축 하기
[root@ruo91 ~]# tar cvzf ruo91.tar.gz /home/ruo91/public_html
z 옵션 추가

tar.bz2 압축 하기
[root@ruo91 ~]# tar cvjf ruo91.tar.bz2 /home/ruo91/public_html
j 옵션 추가



tar 압축 풀기

[root@ruo91 ~]# tar xvf ruo91.tar /home/ruo91/public_html
xvf 옵션 추가

tar.gz 압축 풀기
[root@ruo91 ~]# tar xzvf ruo91.tar.gz /home/ruo91/public_html
z 옵션 추가

tar.bz2 압축 풀기
[root@ruo91 ~]# tar xvjf ruo91.tar.bz2 /home/ruo91/public_html
j 옵션 추가



선택적으로 여러개 파일이나 디렉토리 압축하기
/home/ruo91/public_html 디렉토리의 1, 2, 3, 4, 5 파일 중 1, 2, 5 선택 압축
[root@ruo91 ~]# tar cvf ruo91.tar /home/ruo91/public_html/{1,2,5}
[root@ruo91 ~]# tar cvzf ruo91.tar.gz /home/ruo91/public_html/{1,2,5}
[root@ruo91 ~]# tar cvjf ruo91.tar.bz2 /home/ruo91/public_html/{1,2,5}



해당 파일을 퍼미션 유지 하면서 압축 하기
퍼미션을 유지하기 위해서는 -p 옵션을 사용하면 됩니다.

현재 퍼미션을 모두 제거
[root@ruo91 ~]# chmod 0 /home/ruo91/public_html/4
[root@ruo91 ~]# ls -l /home/ruo91/public_html/4
---------- 1 root root 1 11월 9 14:04 /home/ruo91/public_html/4

현재 퍼미션을 읽기(r), 쓰기(w), 실행(x) 위임
[root@ruo91 ~]# chmod +rwx /home/ruo91/public_html/4
[root@ruo91 ~]# ls -l /home/ruo91/public_html/4
-rwxr-xr-x 1 root root 1 11월 9 14:04 /home/ruo91/public_html/4

설정 된 퍼미션 그대로 보존하고 압축 시도
[root@ruo91 ~]# tar cvf ruo91.tar /home/ruo91/public_html/4

현재 디렉토리에 ruo91.tar 압축 해제
[root@ruo91 ~]# tar xvf ruo91.tar

압축푼 파일 퍼미션 확인
[root@ruo91 ~]# ls -l ~/home/ruo91/public_html/4
-rwxr-xr-x 1 root root 1 11월 9 14:04 /root/home/ruo91/public_html/4

No comments: