관리 메뉴

피터의 개발이야기

[Linux] tar명령어 사용법, tar 압축 풀기 본문

Linux

[Linux] tar명령어 사용법, tar 압축 풀기

기록하는 백앤드개발자 2022. 10. 1. 17:32
반응형

ㅁ 개요

 ㅇ 자주 사용하는 tar 명령어를 정리하였다. 

 ㅇ tar, tar.gz로 압축 및 해제에 대한 방법을 설명한다.

 

 

ㅁ tar로 압축하기

$ tar -cvf [파일명.tar] [폴더명]

ㅇ temp 폴더를 temp.tar로 압축하였다.

 

 

ㅁ tar 압축 풀기

 tar -xvf [파일명.tar]

  ㅇ temp.tar라는 tar파일을 풀었다.

 

 

ㅁ tar.gz로 압축하기

 tar -zcvf [파일명.tar.gz] [폴더명]

ㅇ temp라는 폴더를 temp.tar.gz로 압축하였다.

 

 

ㅁ tar.gz 압축 풀기

tar -zxvf [파일명.tar.gz]

  ㅇ temp.tar.gz라는 tar.gz파일 압축파일을 풀었다.

 

 

ㅁ 용량비교

 ㅇ tar.gz이 압축률이 더 높은 것을 알 수 있다. 

 

 

 

ㅁ 옵션 정리

 옵션 사용법
 -c  파일을 tar로 묶음
 -f 파일 이름을 지정 (기본 옵션)
 -v  묶거나 파일을 풀 때 과정을 화면으로 출력
 -f  파일 이름을 지정
 -C 대상 디렉토리 경로를 지정
 -x  tar 압축을  풀기
 -z  gzip으로 압축하거나 해제함
 -p 파일 권한을 저장
 -j bzip2 압축 적용 옵션
 -A  지정된 파일을 tar 아카이브에 추가
 -d tar 아카이브와 파일 시스템 간 차이점 검색
 -r tar 아카이브의 마지막에 파일들 추가
 -u tar 아카이브의 마지막에 파일들 추가.
 -k tar 아카이브 추출 시, 기존 파일 유지.
 -U tar 아카이브 추출 전, 기존 파일 삭제
-w 모든 진행 과정에 대해 확인 요청(interactive)
-e 첫 번째 에러 발생 시 중지
 

 ㅁ tar help

$ tar --help
tar(bsdtar): manipulate archive files
First option must be a mode specifier:
  -c Create  -r Add/Replace  -t List  -u Update  -x Extract
Common Options:
  -b #  Use # 512-byte records per I/O block
  -f <filename>  Location of archive
  -v    Verbose
  -w    Interactive
Create: tar -c [options] [<file> | <dir> | @<archive> | -C <dir> ]
  <file>, <dir>  add these items to archive
  -z, -j, -J, --lzma  Compress archive with gzip/bzip2/xz/lzma
  --format {ustar|pax|cpio|shar}  Select archive format
  --exclude <pattern>  Skip files that match pattern
  -C <dir>  Change to <dir> before processing remaining files
  @<archive>  Add entries from <archive> to output
List: tar -t [options] [<patterns>]
  <patterns>  If specified, list only entries that match
Extract: tar -x [options] [<patterns>]
  <patterns>  If specified, extract only entries that match
  -k    Keep (don't overwrite) existing files
  -m    Don't restore modification times
  -O    Write entries to stdout, don't restore to disk
  -p    Restore permissions (including ACLs, owner, file flags)
bsdtar 3.3.2 - libarchive 3.3.2 zlib/1.2.11 liblzma/5.0.5 bz2lib/1.0.6

 ㅇ tar help를 통해 사용법을 바로 확인할 수 있다.

반응형

'Linux' 카테고리의 다른 글

[linux] find 사용법  (0) 2024.04.13
[Linux] 리눅스 시간을 한국(KST)로 바꾸기  (0) 2022.08.24
[linux] CentOS 버전 확인하기  (0) 2021.02.05
[linux] awk 사용법  (0) 2020.12.29
[linux] grep 사용법  (0) 2020.12.28
Comments