File archive / Compress - 11주차 수업 - 1
파일 아카이브(tar)
tar - Tape Archive의 약자. Archive의미: 보관소, 저장소
tar [-cxtv] [-f archive] 보관할 파일명
ex) tar -xvf archive.tar libe.html User_Guide.ps
-c Creates an archive
-x Extracts files from archive
-t Display files in archive
-v Display the progress(verbose)
-f archive Specifying the name of archive
-c 특정 디렉토리로 이동하여 아카이브를 해제하는 명령어
파일 압축(gzip)
파일 압축 - gzip
ex) gzip be.html
gzip -d 압축 해제(decompress)
압축 해제 - unzip
ex) gunzip bc.html.gz
파일 압축(zip)
파일 압축 - zip
ex) zip a.zip b.html c.html
압축 해제 - unzip
ex) unzip a.zip
파일 압축(bzip2)
bzip [-dtvbf] 파일명
-d 파일 압축을 해제
-t 압축 파일 검사
-v 압축 정보를 화면에 출력
--best 최대한 압축
--fast 속도 우선
오픈 소스 압축명령, gzip, zip에 비해 압축률은 높지만 속도는 약간 느리다.
압축 해제 - bunzip2 파일명, 확장자가 .bz2인 압축 파일 해제
파일 압축 - compress
확장자가 .Z인 압축 파일 생성
compress [-vc] 파일명
-v 압축 관련 정보 출력
-c 압축 결과를 화면에 출력 .Z 파일 생성 안함
압축 풀기 - uncompress
uncompress [-c] 파일명
-c 복원 결과를 화면에 출력
실습1(tar) *retry
1. /etc/skel* 파일들을 모두 묶어 skelA.tar로 생성
tar -cvf skelA.tar /etc/skel/*
skelA.tar
/etc/skel 디렉토리로 이동
2. 현재 디렉토리의 모든 파일들을 묶어 홈 디렉토리 아래에 skelB.tar로 생성
tar -cvf ~/skelB.tar .
skelB.tar
3. skelA.tar와 skelB.tar에 들어 있는 파일 목록을 비교하라.
cmp skelA.tar skelB.tar
skelA.tar skelB.tar differ: byte 1, line 1
4. 홈 디렉토리 아래에 각각 myskelA와 myskelB 디렉토리를 생성하고 skelA.tar, skelB.tar를 각각의 디렉토리 밑에 파일을 풀어 생성하고 결과를 말하시오.
tar -xvf skelA.tar -C myskelA ; tar -xvf skelB.tar -C myskelB
diff -r myskelA myskelB
Only in myskelB: .bash_logout
Only in myskelB: .bashrc
Only in myskelB: .kshrc
Only in myskelB: .profile
Only in myskelA: etc
Only in myskelB: public_html
myskelA는 홈 디렉토리에서 tar 명령을 해서 복사해왔기 때문에 '.~~'파일들은 사용자 환경 파일로 간주되서 복사되지 않기 때문에 myskelA에 복사되지 않는 것이고, myskelB는 /etc/skel 디렉토리에서 tar 명령 수행 후 가져왔기 때문에 환경설정 파일들이 복사가 가능하다.
실습2(gzip, zip) *retry
1. 자신의 홈 디렉토리 아래에 /etc/services 파일을 복사
cp /etc/services ~/
2. services파일을 gzip으로 압축
gzip services
3. 압축된 파일과 원본 파일 크기 비교
ls -l services services.gz
14464 services
5903 services.gz(deflated 59.2%)
4. 압축 해제
gunzip services.gz
5. services 파일을 zip으로 압축
zip services.zip services
6. 압축된 파일과 원본 파일 크기 비교
ls -l services services.zip
14464 services
6042 services.zip (deflated 59%)
7. 압축 해제
unzip services.zip
실습3(bzip2, compress)
1. 자신의 홈 디렉토리 아래에 /etc/services 파일을 복사
cp /etc/services ~/
2. services 파일을 bzip2로 압축
bzip2 services
3. 압축된 파일과 원본 파일 비교
ls -l services services.bz2
14464 services
5624 services.bz2(deflated 62%)
4. services파일을 compress로 압축
compress services
5. 압축된 파일과 원본 파일 크기 비교
14464services
7833 services.Z(deflated 46%)
실습4
1. /etc/profile.d 디렉토리를 자신의 홈 디렉토리 아래에 Archive 라는 이름의 디렉토리로 복사
cp -r /etc/profile.d ~/Archive
2. Archive디렉토리를 tar을 이용해서 묶음
tar -cvf Archive.tar Archive
3. Archive.tar 파일에 대해 비교
3-1. 3297 Archive.tar.gz(deflated 80%)
3-2. 3439 Archive.tar.gz(deflated 84%)
3-3. 3368 Archive.tar.bz2(deflated 80%)