티스토리 뷰

: tar 명령어는 파일이나 디렉토리를 하나의 파일로 묶는다. 

파일을 백업하거나 전송할때 편하게 하나의 파일로 묶을 때 주로 쓰인다.

 

*사용법: tar[옵션] 파일명1 파일명2

 

[옵션]

파일명1 : 일을 압축이나 묶음으로 만들어진 결과물로 나올 파일명을 지정한다.

 

파일명2 : 압축이나 묶음으로 만들 파일들을 지정한다.

 

-x 아카이브로부터 파일을 푼다.

 

-c 새로운 아카이브를 만듬

 

-v 처리되는 과정의 상세 정보를 보여줌

 

-z gzip으로 압축, ungzip으로 압축해제

 

-j bzip2를 이용해 압축

 

-t 아카이브  되는 목록을 보여줌

 

-d 아카이브와 파일 시스템간의 차이점을 비교

 

-f 옵션 다음 이름 지정으로, 기본값으로 설정된 이름을 변경 가능.

 

-r 아카이브 끝에 새로운 파일을 추가적으로 생성

 

-u 아카이브된 것에 비교하여 새로운 파일만 추가

 

-A 아카이브에 tar 파일을 추가한다.

 

-w 모든 동작에 확인을 하도록 함.

 

--help 도움말보기

 

--version 버전정보보기

 

 

 

  • 파일묶기

 [root@devman tomcat7]# pwd
/usr/local/tomcat7
[root@devman tomcat7]# ls
LICENSE  NOTICE  RELEASE-NOTES  RUNNING.txt  bin  conf  lib  logs  temp  webapps  work
[root@devman tomcat7]# tar -cf backup.tar webapps/
[root@devman tomcat7]# ls -alh
합계 133M
drwxr-xr-x.  9 root root 4.0K 2017-03-20 23:36 .
drwxr-xr-x. 14 root root 4.0K 2017-03-14 18:10 ..
-rw-r--r--.  1 root root 1.4K 2015-10-09 17:41 .gitignore
-rw-r--r--.  1 root root  56K 2015-10-09 17:38 LICENSE
-rw-r--r--.  1 root root 1.3K 2015-10-09 17:38 NOTICE
-rw-r--r--.  1 root root 8.8K 2015-10-09 17:38 RELEASE-NOTES
-rw-r--r--.  1 root root  16K 2015-10-09 17:38 RUNNING.txt
-rw-r--r--   1 root root 133M 2017-03-20 23:36 backup.tar
drwxr-xr-x.  3 root root 4.0K 2016-12-17 09:49 bin
drwxr-xr-x.  3 root root 4.0K 2017-03-20 13:36 conf
drwxr-xr-x.  2 root root 4.0K 2017-03-15 10:43 lib
drwxr-xr-x.  2 root root  24K 2017-03-20 13:38 logs
drwxr-xr-x.  2 root root 4.0K 2017-03-15 13:59 temp
drwxr-xr-x. 13 root root 4.0K 2017-03-20 13:37 webapps
drwxr-xr-x.  3 root root 4.0K 2015-11-10 16:03 work

 

 

  • 파일보기[미리보기]

 [root@devman tomcat7]# tar -tvf backup.tar | more
drwxr-xr-x root/root         0 2017-03-20 13:37 webapps/
drwxr-xr-x root/root         0 2017-01-02 23:56 webapps/realestate/
drwxr-xr-x root/root         0 2016-10-17 09:47 webapps/realestate/jmobile/
-rw-r--r-- root/root    200143 2016-11-23 00:11 webapps/realestate/jmobile/jquery.mobile-1.4.5.min.js
-rw-r--r-- root/root    149156 2016-11-23 00:11 webapps/realestate/jmobile/jquery.mobile.inline-png-1.4.5.css
-rw-r--r-- root/root     68712 2016-11-23 00:11 webapps/realestate/jmobile/jquery.mobile.structure-1.4.5.min.css
-rw-r--r-- root/root    235912 2016-11-23 00:11 webapps/realestate/jmobile/jquery.mobile-1.4.5.min.map
-rw-r--r-- root/root     90835 2016-11-23 00:11 webapps/realestate/jmobile/jquery.mobile.external-png-1.4.5.min.css
-rw-r--r-- root/root    465716 2016-11-23 00:11 webapps/realestate/jmobile/jquery.mobile-1.4.5.js
-rw-r--r-- root/root    122128 2016-11-23 00:11 webapps/realestate/jmobile/jquery.mobile.external-png-1.4.5.css
-rw-r--r-- root/root    127053 2016-11-23 00:11 webapps/realestate/jmobile/jquery.mobile.icons-1.4.5.min.css
drwxr-xr-x root/root         0 2016-10-17 09:47 webapps/realestate/jmobile/images/
-rw-r--r-- root/root      6242 2016-11-23 00:11 webapps/realestate/jmobile/images/ajax-loader.gif
drwxr-xr-x root/root         0 2016-10-17 09:47 webapps/realestate/jmobile/images/icons-svg/
-rw-r--r-- root/root       682 2016-11-23 00:11 webapps/realestate/jmobile/images/icons-svg/arrow-u-white.svg
-rw-r--r-- root/root       793 2016-11-23 00:11 webapps/realestate/jmobile/images/icons-svg/cloud-white.svg
-rw-r--r-- root/root       736 2016-11-23 00:11 webapps/realestate/jmobile/images/icons-svg/comment-black.svg

 

 

  • 해제[묶음풀기]

[root@devman tomcat7]# tar -xvf backup.tar

 

  • 압축[묶음압축하기]

[root@devman tomcat7]# tar -czvf backup.tar.gz webapps/

 

  • 압축풀기[묶음압축해제]

[root@devman tomcat7]# tar -xzvf backup.tar.gz

 

 

 

 

 

 

 

 

 

 

 

 

 

댓글