linux 로 서비스하니 tar.gz 로 압축해서 로그를 전달 받게 된다. 오랜만에 tar 를 써보니 파라미터가 생각나지 않아 메모해둔다.

$ tar --help
Usage: tar [OPTION...] [FILE]...
GNU 'tar' saves many files together into a single tape or disk archive, and can
restore individual files from the archive.

Examples:
  tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.
  tar -tvf archive.tar         # List all files in archive.tar verbosely.
  tar -xf archive.tar          # Extract all files from archive.tar.
$ ls
test2.txt

$ tar -cvf test2.tar test2.txt
test2.txt

$ ls
test2.tar  test2.txt

생성할 때는 c 옵션을 사용하게 된다.

  -c, --create               create a new archive
  -v, --verbose              verbosely list files processed
  -f, --file=ARCHIVE         use archive file or device ARCHIVE

c : 생성
v : 진행중인 파일 표시
f : 파일로 저장

$ tar -czvf test2.tar.gz test2.txt
test2.txt

$ ls
test2.tar  test2.tar.gz  test2.txt

압축을 하고 싶다면 z 옵션을 사용하면 된다.

  -z, --gzip, --gunzip, --ungzip   filter the archive through gzip

z : gzip 을 이용해 압축

$ tar -xvf test2.tar
test2.txt

묶인 파일 해제는 x 명령어를 사용한다.

$ tar -xzvf test2.tar.gz
test2.txt

gzip 으로 압축된 파일을 z 옵션을 추가해줘야 한다.

 Main operation mode:

  -A, --catenate, --concatenate   append tar files to an archive
  -c, --create               create a new archive
      --delete               delete from the archive (not on mag tapes!)
  -d, --diff, --compare      find differences between archive and file system
  -r, --append               append files to the end of an archive
  -t, --list                 list the contents of an archive
      --test-label           test the archive volume label and exit
  -u, --update               only append files newer than copy in archive
  -x, --extract, --get       extract files from an archive

다른 옵션 들도 많으니 tar --help 를 참고하자.

참고 : https://eehoeskrap.tistory.com/555

 

[Linux] tar / tar.gz / zip 압축 및 압축 해제

보통 리눅스에서 파일을 압축 파일을 다룰 때, "tar로 압축(compress)한다"는 표현을 쓰는 경우가 많은데, 정확히 말하자면 tar 자체는 "데이터의 크기를 줄이기 위한 파일 압축"을 수행하지 않는다.

eehoeskrap.tistory.com

 

728x90

+ Recent posts