본문 바로가기
Linux

Linux 파일 압축/풀기

by owo_v 2020. 9. 22.
파일 압축 명령어

xz : 확장명 xz로 압축하거나 풀어줌. 비교적 최신 압축 명령이며 압축률이 뛰어남
-d 파일이름.xz : '파일이름.xz'압축 파일을 일반 파일인 '파일이름'으로 만듦
-l 파일이름.xz : 압축 파일에 포함된 파일 목록과 압축률 등을 출력
-k 파일이름.xz : 압축 후에 기존 파일을 삭제하지 않고 그대로 둠
bzip : 확장명 bzip로 압축하거나 풀어줌

gzip : 확장명 gzip로 압축하거나 풀어줌.

zip : Windows용과 호환되는 확장명 zip로 압축하거나 풀어줌

tar : 확장명 tar로 묶음 파일을 만들거나 묶음을 풀어줌
c(소문자) : 새로운 묶음을 만듦
x : 묶인 파일을 풀어줌
t : 묶음을 풀기 전에 묶인 경로를 보여줌
C(대문자) : 묶음을 풀 때 지정된 디렉터리에 압축을 풀어줌. 지정하지 않으면 묶을 때와 동일한 디렉터리에 묶음이 풀림
-옵션-
f(필수옵션/꼭 붙여야한다) : 묶음 파일 이름 지정. 원래 tar는 테이프 장치 백업이 기본임(생략하면 테이프로 보내짐)
v : visual의 의미로 파일이 묶이거나 풀리는 과정을 보여줌(생략가능)
J(대문자) : tar + xz
j(소문자) : tar + bzip2
z(소문자) : tar + gzip

[root@localhost ~]# pwd
/root
[root@localhost ~]# cd compress_test/
[root@localhost compress_test]# ls
all.tar.xz  comp2.tar  my.tar.bz2  my.tar.xz  test2.txt  test4.txt
all.xz      files      my.tar.gz   test.txt   test3.txt
[root@localhost compress_test]# mkdir xz
[root@localhost compress_test]# mkdir bz2
[root@localhost compress_test]# mkdir gz

-폴더를 만들고 각 폴더에 파일을 풀기

[root@localhost compress_test]# tar Cxvfz ./gz/ my.tar.gz
test.txt
test2.txt
test3.txt
test4.txt
[root@localhost compress_test]# tar xvfj my.tar.bz2 -C ./bz2/
test.txt
test2.txt
test3.txt
test4.txt
[root@localhost compress_test]# tar CxvfJ ./gz/ my.tar.xz
test.txt
test2.txt
test3.txt
test4.txt
[root@localhost compress_test]# ls
all.tar.xz  bz2        files  my.tar.bz2  my.tar.xz  test2.txt  test4.txt
all.xz      comp2.tar  gz     my.tar.gz   test.txt   test3.txt  xz

-3개의 폴더를 압축

[root@localhost compress_test]# tar cvfJ all.tar.xz xz gz bz2
xz/
gz/
gz/test.txt
gz/test2.txt
gz/test3.txt
gz/test4.txt
bz2/
bz2/test.txt
bz2/test2.txt
bz2/test3.txt
bz2/test4.txt
[root@localhost compress_test]# ls
all.tar.xz  bz2        files  my.tar.bz2  my.tar.xz  test2.txt  test4.txt
all.xz      comp2.tar  gz     my.tar.gz   test.txt   test3.txt  xz

-폴더를 삭제하고 compress_test에 아까 폴더들을 묶은 압축파일을 풀기 삭제했던 폴더들이 다시 생기는 것을 확인할 수 있다

[root@localhost compress_test]# rm -rf gz
[root@localhost compress_test]# rm -rf xz
[root@localhost compress_test]# rm -rf bz2
root@localhost compress_test]# ls
all.tar.xz  comp2.tar  my.tar.bz2  my.tar.xz  test2.txt  test4.txt
all.xz      files      my.tar.gz   test.txt   test3.txt
[root@localhost compress_test]# tar xfJ all.tar.xz
[root@localhost compress_test]# ls
all.tar.xz  bz2        files  my.tar.bz2  my.tar.xz  test2.txt  test4.txt
all.xz      comp2.tar  gz     my.tar.gz   test.txt   test3.txt  xz

-압축파일들을 압축했던 압축파일 풀기

[root@localhost compress_test]# rm -rf my*
[root@localhost compress_test]# ls
all.tar.xz  bz2        files  test.txt   test3.txt  xz
all.xz      comp2.tar  gz     test2.txt  test4.txt
[root@localhost compress_test]# tar xfJ all.xz
[root@localhost compress_test]# ls
all.tar.xz  bz2        files  my.tar.bz2  my.tar.xz  test2.txt  test4.txt
all.xz      comp2.tar  gz     my.tar.gz   test.txt   test3.txt  xz

'Linux' 카테고리의 다른 글

Linux 명령어  (0) 2020.09.29
Linux 셀 스크립트 프로그래밍  (0) 2020.09.28
Linux 파이프, 필터.리디렉션  (0) 2020.09.23
Linux cron/at  (0) 2020.09.23
Linux 포그라운드/백그라운드  (0) 2020.09.23

댓글