[압축 프로그램]
Archiving and Compress(묶음과 압축)
☞리눅스 관련 프로그램은 압축된 상태로 인터넷에 올려진 경우가 대부분 이므로 압축명령어를 사용할 수 있어야 한다.
1) tar(압축 기능은 없고 여러 개의 파일을 하나로 묶는 역할을 함)
압축 압축해제
2) gzip , gunzip
3) bzip2 , bunzip2
4) compress , uncompress
5) zip , unzip
☞tar 에서 gzip, bzip2, compress 는 옵션이 지원되고 zip 는 tar 에서 옵션이 지원되지 않는다.
☞압축 해제시 압축 명령어의 -d 옵션(decompress)을 이용할 수 도 있다.
(gzip -d 파일명, bzip2 -d 파일명, compress -d 파일명)
(zip 는 예외로 unzip 을 이용해야 한다.)
//////////////////////////////////////////////////////
♠tar 명령어 형식
tar 옵션(-는 생략가능) 대상파일 원본파일
(cp 와는 반대이다.)
☞tar 는 압축은 하지 않고 여러 파일을 하나로 묶어주거나 해제하는 프로그램
tar 와 몇몇 명령어는 옵션을 줄 때 - 를 생략할 수 있다.
☞옵션의 순서는 변경해도 된다.
☞zxvf 대신 xvfz 를 사용해도 결과는 똑같다.
z : gzip 사용
x : extract (타르 해제)
v : verbose (자세히 출력)
f : file 지정
t : content(내용) 출력
c : create (타르 파일 생성)
j : bzip2 사용
//////////////////////////////////////////////////////
#man tar
NAME
tar - The GNU version of the tar archiving utility
Operations:
[-]A --catenate --concatenate
[-]c --create
[-]d --diff --compare
[-]r --append
[-]t --list
[-]u --update
[-]x --extract --get
--delete
Common Options:
-C, --directory DIR
-f, --file F
-j, --bzip2
-p, --preserve-permissions
-v, --verbose
-z, --gzip
-p, --same-permissions, --preserve-permissions
extract all protection information
-g, --listed-incremental
create/list/extract new GNU-format incremental backup
♠tar 테스트
/
|
+--------+-------+
tmp boot
#tar -cvf /tmp/my1.tar /boot
#ls /tmp
#tar c /tmp/my2.tar /boot
---> f 옵션을 생략하면 화면상에 결과가 출력된다.
가상머신 터미널에서 실행하면 프롬프트가 깨지므로 터미널을 종료후 다시 실행하면 된다.
#ls /tmp
---> f 옵션을 생략해서 파일이 생성되지 않는다.
#tar cf /tmp/my3.tar /boot
---> v 옵션을 생략하면 처리과정이 자세히 출력되지 않는다.
#ls /tmp
#tar cvf /tmp/my5.tar /boot
#ls /tmp
#tar zcvf /tmp/boot.tar.gz /boot
또는
#tar -zcvf /tmp/boot.tar.gz /boot
--->/boot 디렉토리의 모든 내용을 /tmp 디렉토리에 boot.tar.gz 파일로 저장 (tar 로 묶고 gzip 으로 압축이 한꺼번에 된다.)
tar 옵션
z : gzip 사용
c : create
v : verbose
f : file
j : bzip2 사용
p : 퍼미션 보존
t : 내용 출력
#cd /tmp
#ll
#ls -hl
#tar ztvf boot.tar.gz
t : 파일이 풀리는 것이 아니라 내용을 확인하는 옵션
tar 파일의 내용을 볼 때는 tar tvf test.tar 형식을 사용
tar.bz2 파일의 내용을 볼 때는 tar jtvf test.tar.bz2
#ls
tar.gz 파일은 gunzip 으로 압축을 풀고 tar xvf 로 tar 파일을 풀 수도 있지만 tar zxvf 옵션을 이용하면 압축과 tar 해제가 한 번에 된다.
#tar zxvf boot.tar.gz
기본적으로 현재 디렉토리에 파일이 풀린다.
#ls
boot
#tar zxvf boot.tar.gz
#tar zxvf boot.tar.gz -k
기본적으로 덮어쓰기 하므로 기존 파일을 보존하려면 -k 옵션을 이용한다.
#man tar
-k 옵션
-k, --keep-old-files
keep existing files; don’t overwrite them from archive
#gunzip boot.tar.gz (압축해제) 또는 gzip -d boot.tar.gz
#ls
boot.tar
#tar xvf boot.tar (타르 풀기)
---> 기본적으로 현재 디렉토리에 풀리고 다른 디렉토리에 풀려면 "-C 경로" 를 지정하면 된다.
tar 에 -C(대문자) 옵션이 존재하고 gunzip 에는 -C 옵션이 없다.
#gunzip --help
#mkdir /mywork
#tar xvf boot.tar -C /mywork
---> tar 파일이 /mywork 디렉토리에 풀린다.
---> -C (Change) 는 대문자이다.
#ls /mywork
//////////////////////////////////////////////////////
타르 파일과 타르.압축 파일의 생성 형식
tar cvf 파일명.tar
tar zcvf 파일명.tar.gz
tar jcvf 파일명.tar.bz2
타르 파일과 타르.압축 파일의 해제 형식
tar xvf 파일명.tar
tar zxvf 파일명.tar.gz
tar jxvf 파일명.tar.bz2
//////////////////////////////////////////////////////
#tar cvf /tmp/boot2.tar /boot
---> /boot 디렉토리의 모든 내용을 /tmp 의 boot2.tar 파일로 저장하기
압축옵션이 없으므로 압축은 되지 않는다.
c : create
v : verbose
f : file
#cd /tmp
#pwd
(/tmp)
#ls
#bzip2 boot2.tar (bzip2 로 압축)
#gzip my1.tar (gzip 으로 압축)
#ll
#ls -hl
boot.tar
boot2.tar.bz2
my1.tar.gz
(h 옵션을 주면 킬로바이트,메가바이트 형태로 출력 된다.)
#bunzip2 boot2.tar.bz2(압축해제) 또는 bzip2 -d boot2.tar.bz2
#ls -hl
boot.tar
boot2.tar
#tar jcvf /tmp/boot3.tar.bz2 /boot
---> tar 로 묶고 bzip2 로 압축
#pwd
(/tmp)
#ls
boot.tar boot2.tar boot3.tar.bz2
#tar jxvf boot3.tar.bz2
---> 압축 해제하고 타르 풀기
#ls /work5 (디렉토리 없으면 #mkdir /work5 로 생성)
#cp boot3.tar.bz2 /work5
#cd /work5
#ls
#man bunzip2
-k --keep
Keep (don’t delete) input files during compression or decompression.
--->압축 해제시 원본 파일을 삭제하지 않는 옵션(keep)
gunzip 은 -k 옵션이 없음(gunzip --help)
#bunzip2 -k boot3.tar.bz2
#ls
#cd /tmp
#pwd
(/tmp)
#ls
boot.tar boot2.tar boot3.tar.bz2
#gzip boot2.tar (gzip 으로 타르 파일 압축)
#ls
boot.tar boot2.tar.gz boot3.tar.bz2
#file boot.tar
#file boot2.tar.gz
#file boot3.tar.bz2
---> file 명령을 이용하여 파일의 종류를 확인 할 수 있다.
☞tar 파일에서 특정 파일삭제 :
tar --delete -f 타르파일 지울파일명
#tar --delete -f boot.tar message
tar: message: 아카이브에 없음
tar: Error exit delayed from previous errors
#tar tvf boot.tar
#tar --delete -f boot.tar boot/message
☞tar 파일에서 특정 파일만 추출 할 때 :
tar xvf 타르파일 특정파일명
#cd /tmp
#pwd
(/tmp)
#rm -rf boot (rm -rf /boot 하면 부팅이 안 됨)
---> /tmp 폴더 안의 boot 폴더 삭제
#tar xvf boot.tar message.ja
tar: message.ja: 아카이브에 없음
tar: Error exit delayed from previous errors
#tar xvf boot.tar boot/message.ja
boot/message.ja
#ls
#ls boot
message.ja
☞기존의 tar 파일에 새로운 파일 추가하기
(옵션 r 또는 u 사용)
#tar --help
-r, --append 아카이브 끝에 파일을 추가합니다
-u, --update 아카이브 안의 것보다 새로운 파일만 추가합니다
#pwd
(/tmp)
#cp /etc/hosts new.txt
#tar uvf boot.tar new.txt
#tar tvf boot.tar
☞압축된 상태에서는 tar 파일에 새로운 파일을 추가할 수 없다.
[root@cent tmp]# tar uvf boot2.tar.gz new.txt
tar: 이것은 tar 아카이브처럼 보이지 않습니다
tar: 다음 헤더로 건너 뜀
tar: Archive contains obsolescent base-64 headers
new.txt
tar: Error exit delayed from previous errors
[root@cent tmp]# tar zuvf boot2.tar.gz new.txt
tar: 압축된 아카이브를 갱신할 수 없습니다
더 많은 정보를 보려면 `tar --help' 하십시오.
[root@cent tmp]#
♠GUI 압축관리자 사용하기
1) 파일브라우저 실행
2) /tmp 폴더로 이동해서 압축 파일을 더블클릭하거나
3) 압축파일 선택후 마우스 오른쪽 버튼-"압축 관리자 프로그램으로 열기"를 선택하면 그래픽 압축 프로그램을 사용할 수 있다.
4) "풀기" 버튼을 누르고 압축해제할 디렉토리를 지정한 후 오른쪽 하단 "풀기" 버튼을 누르면 된다.
♠GUI 를 이용한 tar 파일 만들기
/work 의 txt 파일을 /tmp/fedora.tar.gz 로 만들기
#file-roller
1) 위쪽 메뉴아이콘에서 "새로 만들기" 클릭
2) 압축 형식에서 "gzip 으로 압축된 Tar" 선택
3) "다른 폴더 찾아보기" 클릭
4) 왼쪽의 파일시스템 더블클릭하고 오른쪽에서 /tmp 선택
5) 위쪽의 이름: fedora 입력(확장자는 제외)
6) "새로 만들기" 버튼 클릭
7) 새로운창이 나타나면
"더하기" 버튼을 누르고 원하는 파일을 선택후 종료하면 됨. 복수 파일을 선택할 때는 Ctrl 키 사용
♠compress 사용하기
#rpm -qa | grep compress
--->설치된 프로그램 확인 방법
#yum -y install ncompress
--->인터넷 서버를 이용한 프로그램 설치 방법
compress 프로그램이 없을 경우 인터넷 프로그램 서버에서 다운을 받아 설치후 실습을 한다.
--->다운이 안되면 리눅스 인터넷 설정을 다시 한 후 해 본다.
#rpm -qa | grep compress
프로그램 설치 확인
---> cent공용 을 사용할 경우 위와 같이 프로그램을 설치한 후 실습을 한다.
#cd /work
#compress score.c
---> 압축 되지 않으면 score.c 에 내용을 더 추가한 후 압축해 본다.
size 가 적으면 compress 로 압축되지 않는다.
#ls
#file score.c.Z
#uncompress score.c.Z 또는 compress -d score.c.Z
---> 압축 해제
♠zip 사용하기
#cd /mywork
#pwd
(/mywork)
#cp /etc/hosts 1.txt
#cp /etc/hosts 2.txt
#cp /etc/hosts 3.txt
#ls
#zip -h (도움말 확인)
-1 compress faster -9 compress better
#man zip
587
588 -# Regulate the speed of compression using the
589 specified digit #, where -0 indicates no com-
590 pression (store all files), -1 indicates the
591 fastest compression method (less compression)
592 and -9 indicates the slowest compression method
593 (optimal compression, ignores the suffix list).
594 The default compression level is -6.
595
#zip my.zip *.txt (압축하기)
또는
#zip my.zip 1.txt 2.txt 3.txt
---> 형식 : zip 압축파일명 원본파일명
#ls
#file my.zip
#cp my.zip /tmp
#cd /tmp
#unzip my.zip (압축 해제 하기)
♠wget 명령어
#man wget
WGET(1) GNU Wget WGET(1)
NAME
Wget - The non-interactive network downloader.
SYNOPSIS
wget [option]... [URL]...
DESCRIPTION
GNU Wget is a free utility for non-interactive download of
files from the Web.
♠실습
1. /Desk1 , /Desk2, /Desk3, /Desk4 디렉토리 생성하기
2. 리눅스 웹브라우저 실행 후
아래 주소 입력
http://httpd.apache.org/download.cgi
httpd-2.2.17.tar.gz 와 httpd-2.2.17.tar.bz2 를 다운받기
3. GUI 프로그램 이용하여
httpd-2.2.17.tar.gz 와 httpd-2.2.17.tar.bz2 를
/Desk1, /Desk2 에 압축과 tar 해제하기
4 .터미널에서 명령어 이용하여
httpd-2.2.17.tar.gz 와 httpd-2.2.17.tar.bz2 를
/Desk3, /Desk4 에 압축과 tar 해제하기
웹브라우저에서 다운을 받으면 바탕화면에 저장되고 터미널에서 찾아갈 때는 cd /root/Desktop 하면 된다.
터미널에서 다운을 받으려면 wget 다음에 주소를 적으면 된다.
#wget URL주소
<vmware tool 사용하기>
vmware tool : 리눅스 가상머신의 그래픽 성능을 향상 시키는 프로그램(해상도 조절, 마우스 이동 등)
vmware tool 을 설치하면
1)고해상도를 사용할 수 있다.
2)윈도우와 리눅스간에 마우스 커서를 자동으로 전환할 수 있다.
3)윈도우에서 복사한 내용을 리눅스로 붙여넣기를 할 수 있다.
1.자동마운트 기능 활성화 하기
리눅스메뉴표시줄-프로그램-환경설정-이동식 저장장치
이동식 디스크 항목
[v]"(cdrom 같은)꺼낼수 있는 미디어가 들어오면 마운트" 체크하기 - 닫기 버튼 클릭
--->위에서 두번째 항목
2.vmware 메뉴표시줄-VM-Install VMware Tools 클릭
바탕화면에 "VMware Tools" cdrom 아이콘 나타나는지 확인
(자동마운트 안되면 리눅스를 리부팅 해 본다.)
update 창이 나오면 취소 버튼을 누르고
가상머신 오른쪽 CDROM 아이콘을 클릭한 후
(*)Use ISO Image file 선택 하고
C:\Program Files (x86)\VMware\VMware Workstation\linux.iso 를 입력해 준다.
3.vmware tool 설치 및 해상도 설정하기
[root@cent ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 15G 3.8G 10G 28% /
none 252M 0 252M 0% /dev/shm
/dev/sda3 4.3G 42M 4.1G 1% /home
/dev/hdc 92M 92M 0 100% /media/cdrom
[root@cent ~]#
---> /media/cdrecorder 로 출력될 수 도 있다.
[root@cent ~]# cd /media/cdrom 또는 cd /media/cdrecorder
[root@cent cdrom]# ls
[root@cent cdrom]# cp VMwareTools-x.x.x-x.tar.gz /work
---> CD 의 파일을 하드디스크로 복사하기
tar 의 -C 옵션을 이용하여 다른 디렉토리에 압축 및 타르 해제를 할 수도 있다.
[root@cent cdrom]# cd /work
[root@cent work]# ls
[root@cent work]# tar zxvf VMwareTools-x.x.x-x.tar.gz
---> 압축 프로그램을 해제하는 명령
[root@cent vmware-tools-distrib]# cd vmware-tools-distrib
[root@cent vmware-tools-distrib]# pwd
/work/vmware-tools-distrib
[root@cent vmware-tools-distrib]# ls
FILES INSTALL bin doc etc installer lib vmware-install.pl
vmware-install.pl 프로그램을 실행하고
해상도 설정 질문이
나올 때까지 엔터를 입력해 주면 된다.
(putty에서 하면 안 되고 리눅스 가상머신 터미널에서 해야 함)
[root@cent vmware-tools-distrib]# ./vmware-install.pl
Creating a new VMware Tools installer database using the tar4 format.
Installing VMware Tools.
In which directory do you want to install the binary files?
[/usr/bin] ---> 엔터 입력
... (생략)
[1] "640x480"
[2] "800x600"
...
Please enter a number between 1 and 15 :
[6] 원하는 해상도 번호 선택하기
#reboot
부팅시 "실패" 로 나오는 것은 무시해도 된다.
루트로 로그인
해상도를 다시 조정하려면 터미널에서
#system-config-display 실행 후 변경해 주면 된다
.
엠토리가 수업받은 내용을 쭈욱 적습니다.
이는 처음부터 하나하나 확인하며 따라하기 형태로 공부하면서.. 생기는 화면변화등에 민감히 반응할 수 있어야 자기 것이 될 것입니다.
이상, 엠토리 였습니다. 항상 행.복.하시길~^^
'◇ Tip & Info ◇' 카테고리의 다른 글
엠토리, 리눅스 세상에서 - 9th : 마운트, 쿼타 등 (0) | 2011.03.08 |
---|---|
엠토리, 리눅스 세상에서 - 8th : 프로세스, 패키지 (0) | 2011.03.03 |
엠토리, 리눅스 세상에서 - 6th : 퍼미션과 소유권, 그리고 리눅스 명령어(grep,find) (0) | 2011.02.28 |
엠토리, 리눅스 세상에서 - 5th : Shell(쉘) (0) | 2011.02.23 |
엠토리, 리눅스 세상 접속 - 4th : 여러가지 명령어 (0) | 2011.02.17 |