서버/Linux I 2016. 1. 25. 16:31

Linux I - 11. 압축 & 아카이빙

 

 

 

login as: root
root@192.168.1.2's password:
Last login: Mon Jan 25 16:24:57 2016 from 192.168.1.1
[root@CentOS /root]#
[root@CentOS /root]# mkdir test
[root@CentOS /root]# cd test
[root@CentOS /root/test]#

 

 

 


1. 'gzip' & 'gunzip' & 'zcat' 명령어

 

 - 'gzip' 명령어는 파일을 압축 및 해지할때 사용한다. 이때 확장자는 '.gz'로 되며, 파일의 속성 정보도 유지하여 압축한다.
 - 'gunzip' 명령어는 확장자가 '.gz'로 된 압축 파일 해지 및 압축 파일 내용 확인을 확인 할 수 있다.

 - 'zcat' 명령어는 압축 파일 내용을 확인할 수 있다.

 


[root@CentOS /root/test]# gzip -S          압축 파일을 .gz 파일이 아닌, 다른 파일로 생성
[root@CentOS /root/test]# gzip -d          압축 파일 해지할때 사용
[root@CentOS /root/test]# gzip -f           기존 압축파일이 있어도, 무시하고 압축 파일 생성
[root@CentOS /root/test]# gzip -r           디렉토리이면, 하위 디렉토리 및 파일까지 압축
[root@CentOS /root/test]# gzip -v          압축 통계 출력

 


Ex1) 'gzip' 명령어


[root@CentOS /root/test]# cp /etc/services file1
[root@CentOS /root/test]# cp /etc/services file2
[root@CentOS /root/test]# cp /etc/services file3
[root@CentOS /root/test]# cp /etc/services file4

 

[root@CentOS /root/test]# gzip file1
[root@CentOS /root/test]# ls -l
합계 2012
-rw-r--r--. 1 root root 127220 2016-01-25 17:17 file1.gz
-rw-r--r--. 1 root root 641020 2016-01-25 17:17 file2
-rw-r--r--. 1 root root 641020 2016-01-25 17:17 file3
-rw-r--r--. 1 root root 641020 2016-01-25 17:17 file4

 

[root@CentOS /root/test]# gzip -v file2        // -6 기본값 적용
file2:   80.2% -- replaced with file2.gz

 

[root@CentOS /root/test]# gzip -9v file3      // -9는 압축율은 좋지만, 속도가 느림
file3:   80.3% -- replaced with file3.gz

 

[root@CentOS /root/test]# gzip -1v file4      // -1은 압축율은 나쁘지만, 속도가 빠름
file4:   77.2% -- replaced with file4.gz

 

[root@CentOS /root/test]# ls -l
합계 524
-rw-r--r--. 1 root root 127220 2016-01-25 17:17 file1.gz
-rw-r--r--. 1 root root 127220 2016-01-25 17:17 file2.gz
-rw-r--r--. 1 root root 126611 2016-01-25 17:17 file3.gz
-rw-r--r--. 1 root root 146158 2016-01-25 17:17 file4.gz


[root@CentOS /root/test]# rm -rf file*
[root@CentOS /root/test]# ls

 

 


Ex2) 디렉토리 안에 있는 모든 파일 압축 I

 

[root@CentOS /root/test]# mkdir dir1
[root@CentOS /root/test]# cd dir1
[root@CentOS /root/test/dir1]# cp /etc/services file1
[root@CentOS /root/test/dir1]# cp /etc/services file2
[root@CentOS /root/test/dir1]# cp /etc/services file3
[root@CentOS /root/test/dir1]# cd ..
[root@CentOS /root/test]#

[root@CentOS /root/test]# ls -l dir1
합계 1884
-rw-r--r--. 1 root root 641020 2016-01-25 17:41 file1
-rw-r--r--. 1 root root 641020 2016-01-25 17:41 file2
-rw-r--r--. 1 root root 641020 2016-01-25 17:41 file3

 

[root@CentOS /root/test]# du -sh dir1
1.9M    dir1


[root@CentOS /root/test]# gzip -r dir1
[root@CentOS /root/test]# ls -l dir1
합계 384
-rw-r--r--. 1 root root 127220 2016-01-25 17:41 file1.gz
-rw-r--r--. 1 root root 127220 2016-01-25 17:41 file2.gz
-rw-r--r--. 1 root root 127220 2016-01-25 17:41 file3.gz

 

[root@CentOS /root/test]# du -sh dir1
388K    dir1

 

[root@CentOS /root/test]# rm -rf dir1
[root@CentOS /root/test]# ls

 

 

 

Ex3) 디렉토리 안에 있는 모든 파일 압축 II


[root@CentOS /root/test]# cp -r /var/lib dir1
[root@CentOS /root/test]# du -sh dir1
103M    dir1

 

[root@CentOS /root/test]# ls dir1
DeviceKit-power  cas         fprint            mlocate   postfix      rsyslog    xkb
NetworkManager   certmonger  games             net-snmp  prelink      samba      yum
PackageKit       dav         gdm               nfs       pulse        sss
alternatives     dbus        ipa-client        ntp       random-seed  stateless
authconfig       dhclient    logrotate.status  plymouth  readahead    udev
bluetooth        dnsmasq     misc              polkit-1  rpm          udisks


[root@CentOS /root/test]# ls dir1/yum
history  repos  rpmdb-indexes  uuid  yumdb

[root@CentOS /root/test]# ls dir1/yum/history
2016-01-12  history-2016-01-12.sqlite  history-2016-01-12.sqlite-journal


[root@CentOS /root/test]# gzip -r dir1
gzip: dir1/gdm/.pulse/f7a5ed4dadb57d0f6b6e491f00000023-runtime: Too many levels of symbolic links

[root@CentOS /root/test]# du -sh dir1
63M     dir1

[root@CentOS /root/test]# ls dir1
DeviceKit-power  certmonger  gdm                  ntp             readahead  udisks
NetworkManager   dav         ipa-client           plymouth        rpm        xkb
PackageKit       dbus        logrotate.status.gz  polkit-1        rsyslog    yum
alternatives     dhclient    misc                 postfix         samba
authconfig       dnsmasq     mlocate              prelink         sss
bluetooth        fprint      net-snmp             pulse           stateless
cas              games       nfs                  random-seed.gz  udev


[root@CentOS /root/test]# ls dir1/yum
history  repos  rpmdb-indexes  uuid.gz  yumdb

[root@CentOS /root/test]# ls dir1/yum/history
2016-01-12  history-2016-01-12.sqlite-journal.gz  history-2016-01-12.sqlite.gz

[root@CentOS /root/test]# rm -rf dir1
[root@CentOS /root/test]# ls

 

 

 

Ex4) 'zcat' 명령어를 이용한 압축 파일 내용 확인


[root@CentOS /root/test]# cp /etc/services file1
[root@CentOS /root/test]# gzip file1
[root@CentOS /root/test]# ls -l
합계 128
-rw-r--r--. 1 root root 127220 2016-01-25 17:28 file1.gz

[root@CentOS /root/test]# cat file1.gz
|@▒
▒QI▒▒[▒x▒▒xomi9Z@V▒▒▒l▒R▒0+▒k▒▒▒sY▒w؍▒A▒0;~▒_▒▒▒ѣ*▒▒▒PC▒▒4▒|▒▒5▒▒[b{ئ▒▒Y}!{1▒t2zz▒~▒▒▒▒h▒▒▒G▒▒/▒▒▒▒ѻs▒▒<>▒w>▒T▒-α▒p▒#i▒~X▒UҾWb▒▒xx3▒n▒▒MxT▒▒E▒▒▒')]ݓ▒▒Ǐ▒gJ

 

(ctrl+c)

 

[root@CentOS /root/test]#
[root@CentOS /root/test]# zcat file1.gz | head -n 5   (# gunzip -c file1.gz 동일)
# /etc/services:
# $Id: services,v 1.48 2009/11/11 14:32:31 ovasik Exp $
#
# Network services, Internet style
# IANA services version: last updated 2009-11-10

 

 


Ex5) 'gzip' 명령어를 이용한 압축 파일 해지

 

[root@CentOS /root/test]# gzip -d file1.gz   (# gunzip file1.gz 동일)
[root@CentOS /root/test]# ls -l
합계 628
-rw-r--r--. 1 root root 641020 2016-01-25 17:28 file1


[root@CentOS /root/test]# rm -rf file1
[root@CentOS /root/test]# ls

 

 

 

Ex6) 다수의 파일을 한개로 압축 불가능

 

[root@CentOS /root/test]# cp /etc/services file1
[root@CentOS /root/test]# cp /etc/services file2
[root@CentOS /root/test]# cp /etc/services file3
[root@CentOS /root/test]#
[root@CentOS /root/test]# ls -l
합계 1884
-rw-r--r--. 1 root root 641020 2016-01-25 17:35 file1
-rw-r--r--. 1 root root 641020 2016-01-25 17:35 file2
-rw-r--r--. 1 root root 641020 2016-01-25 17:35 file3

 

[root@CentOS /root/test]# gzip file1 file2 file3
[root@CentOS /root/test]# ls -l
합계 384
-rw-r--r--. 1 root root 127220 2016-01-25 17:35 file1.gz
-rw-r--r--. 1 root root 127220 2016-01-25 17:35 file2.gz
-rw-r--r--. 1 root root 127220 2016-01-25 17:35 file3.gz

 

[root@CentOS /root/test]# gunzip *.gz
[root@CentOS /root/test]# ls -l
합계 1884
-rw-r--r--. 1 root root 641020 2016-01-25 17:35 file1
-rw-r--r--. 1 root root 641020 2016-01-25 17:35 file2
-rw-r--r--. 1 root root 641020 2016-01-25 17:35 file3

 

[root@CentOS /root/test]# rm -rf file*

[root@CentOS /root/test]# ls

 

 

 

3. 'bzip2' & 'bunzip2' 명령어

 

 - 성능이 높은 압축 방식이며, 압축된 파일은 기존 파일의 속성 정보를 그대로 유지한다.
 - tar 아카이브 파일을 압축하면, 기존 아카이브 파일이 제거되고 , bz2 확장자로 생성한다.


[root@CentOS /root/test]# bzip2 -d         압축 파일 해지
[root@CentOS /root/test]# bzip2 -z         파일 압축 실시
[root@CentOS /root/test]# bzip2 -k         압축 및 해지시 같은 이름의 파일 있을 경우, 덮어쓰기 실시
[root@CentOS /root/test]# bzip2 -q         경고 메세지 출력 않함
[root@CentOS /root/test]# bzip2 -v         압축 및 해지 진행 상황 출력

[root@CentOS /root/test]# bunzip2 -c     압축 파일 내용을 확인할때 사용

 


Ex1) 'bzip2'를 이용한 파일 압축

 

[root@CentOS /root/test]# cp /etc/services file1
[root@CentOS /root/test]# cp /etc/services file2

 

[root@CentOS /root/test]# bzip2 file1
[root@CentOS /root/test]# ls -l
합계 744
-rw-r--r--. 1 root root 115774 2016-01-25 18:15 file1.bz2
-rw-r--r--. 1 root root 641020 2016-01-25 18:15 file2

 

[root@CentOS /root/test]# bzip2 -kv file2
  file2:    5.537:1,  1.445 bits/byte, 81.94% saved, 641020 in, 115774 out.


[root@CentOS /root/test]# ls -l
합계 860
-rw-r--r--. 1 root root 115774 2016-01-25 18:15 file1.bz2
-rw-r--r--. 1 root root 641020 2016-01-25 18:15 file2
-rw-r--r--. 1 root root 115774 2016-01-25 18:15 file2.bz2

 

 


Ex2) 'bzcat' 명령어를 이용한 압축 파일 내용 확인

 

[root@CentOS /root/test]# cat file1.bz2
▒▒▒{▒,UUUUp6n▒▒+▒▒Mz▒d▒m▒▒ƞlU>./c▒͒▒▒L▒t▒▒eP▒▒▒(r]4▒▒U▒1▒▒▒▒)þ▒c▒▒▒▒l9+B▒)
▒V▒kIVƵb▒U|▒▒B▒▒▒

 

(ctrl+c)

 

[root@CentOS /root/test]# bzcat file1.bz2 | head -n 5      (# bunzip2 -c file1.bz2)

# /etc/services:
# $Id: services,v 1.48 2009/11/11 14:32:31 ovasik Exp $
#
# Network services, Internet style
# IANA services version: last updated 2009-11-10

 

 


Ex3) 'bzip2' 명령어를 이용한 압축 해지

 

[root@CentOS /root/test]# bzip2 -d file1.bz2   (# bunzip2 file1.bz2)
[root@CentOS /root/test]# ls -l
합계 1372
-rw-r--r--. 1 root root 641020 2016-01-25 18:20 file1
-rw-r--r--. 1 root root 641020 2016-01-25 18:20 file2
-rw-r--r--. 1 root root 115774 2016-01-25 18:20 file2.bz2

 

[root@CentOS /root/test]# bunzip2 file2.bz2
bunzip2: Output file file2 already exists.

 

[root@CentOS /root/test]# ls -l
합계 1372
-rw-r--r--. 1 root root 641020 2016-01-25 18:20 file1
-rw-r--r--. 1 root root 641020 2016-01-25 18:20 file2
-rw-r--r--. 1 root root 115774 2016-01-25 18:20 file2.bz2


[root@CentOS /root/test]# rm -rf file*
[root@CentOS /root/test]# ls 

 

 

 

3. 'tar' 명령어 (압축 & 아카이빙)

 

 - 'tar' 명령어는 여러개의 파일이나 디렉토리를 한개의 묶음 파일로 압축한다. 이를 아카이빙이라고 한다.
 - 이때, 아카이브(archive), 아카이빙(archiving)이라는 단어는 파일을 보관/기록하다는 의미를 갖고 있다.

 

 

 c

 아카이빙 파일 생성

 t

 아카이빙 파일 내용 확인

 x

 아카이빙 파일 해지

f

 아카이빙 파일 지정

v

 진행 과정 보여줌

z

gzip 파일 압축 및 해지 할때 사용

j

 bzip2를 이용해서 압축

l

 bzip2를 이용해서 압축

 

 

 

Ex1) 'tar' 명령어를 이용한 파일 압축, 압축 내용 확인, 압축 해지


[root@CentOS /root/test]# cp /etc/services file1
[root@CentOS /root/test]# cp /etc/services file2
[root@CentOS /root/test]# cp /etc/services file3
[root@CentOS /root/test]#
[root@CentOS /root/test]# ls -l
합계 1884
-rw-r--r--. 1 root root 641020 2016-01-25 18:35 file1
-rw-r--r--. 1 root root 641020 2016-01-25 18:35 file2
-rw-r--r--. 1 root root 641020 2016-01-25 18:35 file3


[root@CentOS /root/test]# tar cvf file.tar file1 file2 file3       file1~file3을 file.tar로 아카이빙 실시
file1
file2
file3

 

[root@CentOS /root/test]# ls -l
합계 3776
-rw-r--r--. 1 root root 1935360 2016-01-25 19:32 file.tar
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file1
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file2
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file3

 

[root@CentOS /root/test]# rm -f file1 file2 file3                   file1~file3 삭제
[root@CentOS /root/test]# ls -l
합계 1892
-rw-r--r--. 1 root root 1935360 2016-01-25 19:32 file.tar

 

[root@CentOS /root/test]# tar tvf file.tar                            file.tar 파일 내용 확인 가능
-rw-r--r-- root/root    641020 2016-01-25 19:32 file1
-rw-r--r-- root/root    641020 2016-01-25 19:32 file2
-rw-r--r-- root/root    641020 2016-01-25 19:32 file3

 

[root@CentOS /root/test]# ls -l
합계 1892
-rw-r--r--. 1 root root 1935360 2016-01-25 19:32 file.tar


[root@CentOS /root/test]# tar xvf file.tar                            file.tar 파일 압축 해지
file1
file2
file3

 

[root@CentOS /root/test]# ls -l
합계 3776
-rw-r--r--. 1 root root 1935360 2016-01-25 19:32 file.tar
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file1
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file2
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file3


[root@CentOS /root/test]# rm -rf file.tar
[root@CentOS /root/test]# ls
file1  file2  file3

 

 

 

Ex2) 'gzip' & 'tar' 명령어를 이용한 다수의 파일 압축 및 해지하기

 

[root@CentOS /root/test]# tar cvf file.tar file1 file2 file3                  file1~file3을 file.tar로 아카이빙 실시
file1
file2
file3

[root@CentOS /root/test]# ls -l
합계 3776
-rw-r--r--. 1 root root 1935360 2016-01-25 19:43 file.tar
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file1
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file2
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file3

 

[root@CentOS /root/test]# gzip file.tar                                       'gzip을 이용하여 'file.tar' 압축 실시
[root@CentOS /root/test]# ls -l
합계 2260
-rw-r--r--. 1 root root 381991 2016-01-25 19:43 file.tar.gz
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file1
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file2
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file3

 

[root@CentOS /root/test]# gzip -d file.tar.gz                               'gzip을 이용하여 'file.tar.gz' 압축 해지
[root@CentOS /root/test]# ls -l
합계 3776
-rw-r--r--. 1 root root 1935360 2016-01-25 19:43 file.tar
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file1
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file2
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file3

 

[root@CentOS /root/test]# rm -f file1 file2 file3                                file1~file3 삭제
[root@CentOS /root/test]# ls
file.tar

 

[root@CentOS /root/test]# tar xvf file.tar                                        file.tar 파일 압축 해지
file1
file2
file3

 

[root@CentOS /root/test]# ls -l
합계 3776
-rw-r--r--. 1 root root 1935360 2016-01-25 19:43 file.tar
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file1
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file2
-rw-r--r--. 1 root root  641020 2016-01-25 19:32 file3

 

[root@CentOS /root/test]# rm -f file.tar
[root@CentOS /root/test]# ls
file1  file2  file3

 

 


Ex3)  'tar' & 'z' 옵션 명령어를 이용한 다수의 파일 압축 및 해지하기

 

[root@CentOS /root/test]# tar cvzf file.tar.gz file1 file2 file3              file1~file3을 gzip을 이용하여 file.tar.gz로 아카이빙 실시
file1
file2
file3

 

[root@CentOS /root/test]# ls -l
합계 2260
-rw-r--r--. 1 root root 381982 2016-01-25 19:47 file.tar.gz
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file1
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file2
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file3


[root@CentOS /root/test]# rm -f file1 file2 file3                                file1~file3 삭제

[root@CentOS /root/test]# ls
file.tar.gz

 

[root@CentOS /root/test]# tar xvzf file.tar.gz                                  gzip을 이용하여 file.tar 파일 압축 해지
file1
file2
file3

 

[root@CentOS /root/test]# ls -l
합계 2260
-rw-r--r--. 1 root root 381982 2016-01-25 19:47 file.tar.gz
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file1
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file2
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file3


[root@CentOS /root/test]# rm -f file.tar.gz
[root@CentOS /root/test]# ls
file1  file2  file3

 

 

 

Ex4) 'tar' & 'b' 옵션 명령어를 이용한 다수의 파일 압축 및 해지하기


[root@CentOS /root/test]# tar cvjf file.tar.bz2 file1 file2 file3           file1~file3을 bzip2를 이용하여 file.tar.bz2로 아카이빙 실시
file1
file2
file3

[root@CentOS /root/test]# ls -l
합계 2140
-rw-r--r--. 1 root root 260464 2016-01-25 19:56 file.tar.bz2
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file1
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file2
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file3

[root@CentOS /root/test]# rm -f file1 file2 file3                                file1~file3 삭제
[root@CentOS /root/test]# ls
file.tar.bz2

[root@CentOS /root/test]# tar xvjf file.tar.bz2                                 bipz2을 이용하여 file.tar 파일 압축 해지
file1
file2
file3

[root@CentOS /root/test]# ls -l
합계 2140
-rw-r--r--. 1 root root 260464 2016-01-25 19:56 file.tar.bz2
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file1
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file2
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file3

[root@CentOS /root/test]# rm -f file.tar.bz2
[root@CentOS /root/test]# ls
file1  file2  file3

 

 

[참고] 'wget'을 이용한 압축 파일 다운로드

 

@ tar 압축 파일 다운로드 사이트.txt

 

 

 

 

4. 'zip' & 'unzip' 명령어

 

 - 윈도우에서 사용하는 zip 압축 방식과 동일하다.

 

Ex1) 'zip'을 이용한 압축 및 해지

 

[root@CentOS /root/test]# zip file.zip file1 file2 file3                       file1~file3을 zip를 이용하여 압축 실시
  adding: file1 (deflated 80%)
  adding: file2 (deflated 80%)
  adding: file3 (deflated 80%)

 

[root@CentOS /root/test]# ls -l
합계 2260
-rw-r--r--. 1 root root 382024 2016-01-25 20:09 file.zip
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file1
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file2
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file3

 

[root@CentOS /root/test]# unzip -l file.zip                                   'unzip -l'을 이용하여 압축 내용 확인
Archive:  file.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
   641020  01-25-2016 19:32   file1
   641020  01-25-2016 19:32   file2
   641020  01-25-2016 19:32   file3
---------                     -------
  1923060                     3 files

 

[root@CentOS /root/test]# rm -f file1 file2 file3                               file1~file3 삭제
[root@CentOS /root/test]# ls
file.zip

 

[root@CentOS /root/test]# unzip file.zip                                       unzip을 이용하여 file.tar 파일 압축 해지
Archive:  file.zip
  inflating: file1
  inflating: file2
  inflating: file3

 

[root@CentOS /root/test]# ls -l
합계 2260
-rw-r--r--. 1 root root 382024 2016-01-25 20:09 file.zip
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file1
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file2
-rw-r--r--. 1 root root 641020 2016-01-25 19:32 file3

 

 

 

Ex2) 'zip'을 이용한 디렉토리 압축 및 아카이빙 I


[root@CentOS /root/test]# cd ..
[root@CentOS /root]# zip -r test.zip test
  adding: test/ (stored 0%)
  adding: test/file3 (deflated 80%)
  adding: test/file1 (deflated 80%)
  adding: test/file2 (deflated 80%)

[root@CentOS /root]# unzip -l test.zip
Archive:  test.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  01-25-2016 20:13   test/
   641020  01-25-2016 19:32   test/file3
   641020  01-25-2016 19:32   test/file1
   641020  01-25-2016 19:32   test/file2
---------                     -------
  1923060                     4 files

[root@CentOS /root]# ls -l
합계 2472
-rw-------. 1 root root    1594 2016-01-12 00:27 anaconda-ks.cfg
-rw-r--r--. 1 root root 2028252 2016-01-11 13:13 cfile4.uf@2752A13656932BE71E15DA.rpm
drwxr-xr-x. 3 root root    4096 2016-01-13 14:50 home
-rw-r--r--. 1 root root     582 2016-01-13 16:22 home.tar.gz
-rw-r--r--. 1 root root   46035 2016-01-12 00:27 install.log
-rw-r--r--. 1 root root   10033 2016-01-12 00:24 install.log.syslog
drwxr-xr-x. 2 root root    4096 2016-01-25 20:13 test
-rw-r--r--. 1 root root  382192 2016-01-25 20:15 test.zip
drwxr-xr-x. 2 root root    4096 2016-01-12 01:03 공

~ 중간 생략 ~

 


[root@CentOS /root]# rm -rf test
[root@CentOS /root]# ls -l
합계 2468
-rw-------. 1 root root    1594 2016-01-12 00:27 anaconda-ks.cfg
-rw-r--r--. 1 root root 2028252 2016-01-11 13:13 cfile4.uf@2752A13656932BE71E15DA.rpm
drwxr-xr-x. 3 root root    4096 2016-01-13 14:50 home
-rw-r--r--. 1 root root     582 2016-01-13 16:22 home.tar.gz
-rw-r--r--. 1 root root   46035 2016-01-12 00:27 install.log
-rw-r--r--. 1 root root   10033 2016-01-12 00:24 install.log.syslog
-rw-r--r--. 1 root root  382192 2016-01-25 20:15 test.zip
drwxr-xr-x. 2 root root    4096 2016-01-12 01:03 공개

~ 중간 생략 ~

 


[root@CentOS /root]# unzip test.zip
Archive:  test.zip
   creating: test/
  inflating: test/file3
  inflating: test/file1
  inflating: test/file2

[root@CentOS /root]# ls -l
합계 2472
-rw-------. 1 root root    1594 2016-01-12 00:27 anaconda-ks.cfg
-rw-r--r--. 1 root root 2028252 2016-01-11 13:13 cfile4.uf@2752A13656932BE71E15DA.rpm
drwxr-xr-x. 3 root root    4096 2016-01-13 14:50 home
-rw-r--r--. 1 root root     582 2016-01-13 16:22 home.tar.gz
-rw-r--r--. 1 root root   46035 2016-01-12 00:27 install.log
-rw-r--r--. 1 root root   10033 2016-01-12 00:24 install.log.syslog
drwxr-xr-x. 2 root root    4096 2016-01-25 20:13 test
-rw-r--r--. 1 root root  382192 2016-01-25 20:15 test.zip
drwxr-xr-x. 2 root root    4096 2016-01-12 01:03 공개
drwxr-xr-x. 2 root root    4096 2016-01-11 16:40 다운로드
drwxr-xr-x. 2 root root    4096 2016-01-12 01:03 문서
drwxr-xr-x. 2 root root    4096 2016-01-13 15:35 바탕화면
drwxr-xr-x. 2 root root    4096 2016-01-12 01:03 비디오
drwxr-xr-x. 2 root root    4096 2016-01-12 01:03 사진
drwxr-xr-x. 2 root root    4096 2016-01-12 01:03 음악
drwxr-xr-x. 2 root root    4096 2016-01-12 01:03 템플릿

 


[root@CentOS /root]# rm -f test.zip
[root@CentOS /root]# rm -rf test
[root@CentOS /root]# mkdir test
[root@CentOS /root]# cd test
[root@CentOS /root/test]# ls

 


 

Ex3) 'zip'을 이용한 디렉토리 압축 및 아카이빙 II

 

[root@CentOS /root/test]# cp -r /etc/sysconfig ./
[root@CentOS /root/test]# ls
sysconfig


[root@CentOS /root/test]# zip -r test.zip sysconfig
        zip warning: name not matched: sysconfig/network-scripts/ifdown
        zip warning: name not matched: sysconfig/network-scripts/ifup
        zip warning: name not matched: sysconfig/selinux
  adding: sysconfig/ (stored 0%)
  adding: sysconfig/httpd (deflated 47%)
  adding: sysconfig/autofs (deflated 34%)
  adding: sysconfig/ip6tables.old (deflated 50%)
  adding: sysconfig/iptables-config (deflated 60%)
  adding: sysconfig/smartmontools (deflated 26%)
  adding: sysconfig/firstboot (stored 0%)

~ 중간 생략 ~

 


[root@CentOS /root/test]# ls
sysconfig  test.zip


[root@CentOS /root/test]# unzip -l test.zip
Archive:  test.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  01-25-2016 20:24   sysconfig/
      947  01-25-2016 20:24   sysconfig/httpd
      339  01-25-2016 20:24   sysconfig/autofs
      560  01-25-2016 20:24   sysconfig/ip6tables.old

~ 중간 생략 ~

 

 

[root@CentOS /root/test]# rm -rf sysconfig
[root@CentOS /root/test]# ls
test.zip


[root@CentOS /root/test]# unzip test.zip
Archive:  test.zip
   creating: sysconfig/
  inflating: sysconfig/httpd
  inflating: sysconfig/autofs
  inflating: sysconfig/ip6tables.old
  inflating: sysconfig/iptables-config
  inflating: sysconfig/smartmontools
 extracting: sysconfig/firstboot

~ 중간 생략 ~

 


[root@CentOS /root/test]# ls
sysconfig  test.zip


[root@CentOS /root/test]# ls sysconfig
atd           init              network-scripts  sandbox
auditd        ip6tables         networking       saslauthd
authconfig    ip6tables-config  nfs              smartmontools
autofs        ip6tables.old     nspluginwrapper  snmpd
cbq           iptables          ntpd             snmptrapd
clock         iptables-config   ntpdate          sshd
console       iptables.old      prelink          sysstat
cpuspeed      irqbalance        quota_nld        sysstat.ioconf
crond         kdump             raid-check       system-config-firewall
firstboot     kernel            readahead        system-config-firewall.old
grub          keyboard          readonly-root    system-config-users
htcacheclean  modules           rngd             udev
httpd         netconsole        rsyslog          wpa_supplicant
i18n          network           samba

 

 


[root@CentOS /root/test]# cd
[root@CentOS /root]# rm -rf test

Posted by 김정우 강사(카카오톡 : kim10322)
,


Q