본문 바로가기
메모/코딩

[리눅스] tar 또는 tar.gz 파일 압축 및 풀기

by 붕붕=33 2024. 8. 24.

리눅스에서 .tar 또는 .tar.gz 파일을 압축 및 압축풀기 할 때마다 헷갈려하다가, 이 기회에 tar commend를 이용한 파일 압축 및 해제 방법을 정리하는 글을 포스팅하겠다.

 


1. 옵션 정리

  • -c: Create a new archive (압축 파일 생성)
  • -v: Verbose output to show progress in the terminal (verbose 정보를 터미널에 출력)
  • -f: Specify the filename of the archive (해당 옵션 뒤에 항상 파일 이름을 입)
  • -z: Compress/Decompress with gzip (-z for gzip, -j for bzip2) (gzip으로 압축/풀기)
  • -x: Extract the archive (파일 압축 풀기)
  • -C: Change to a specific directory before creating/extracting the archive (특정 경로로 이동)

 

2. 파일 압축하기 (-c 옵션 사용)

  • .tar로 압축
tar -cvf archive_name.tar /path/to/directory_or_files

 

  • .tar.gz(Gzipped tar)로 압축
tar -czvf archive_name.tar.gz /path/to/directory_or_files

 

  • 특정 파일 경로를 지정하여 압축
tar -czvf archive_name.tar.gz -C /path/to/files .

새 archive를 생성(create, -c)하기 전에 /path/to/files 디렉토리로 이동(Change to the directory, -C) 후, /path/to/files 경로 내에서의 현재 디렉토리(.)의 파일들을 압축

 

3. 파일 압축풀기 (-x 옵션 사용)

  • .tar 파일 압축풀기
tar -xvf archive_name.tar

 

  • .tar.gz 파일 압축풀기
tar -xzvf archive_name.tar.gz

 

  • 특정 파일 경로를 지정하여 압축풀기
tar -xzvf archive_name.tar.gz -C /path/to/extract/directory

archive_name.tar.gz파일을 /path/to/extract 디렉토리에 압축 풀기

 

 

댓글