tech

Linux - tar, tar.gz, tar.bz2 압축/해제 명령어 정리

tech-lover 2021. 4. 22. 18:47

tar

다음과 같이 파일을 압축하거나 풀 수 있습니다.

압축

$ tar -cvf [output file name] [target1] [target2] [...]
# ex) tar -cvf abc.tar ./folder1 ./folder2 ./folder3
# 옵션 의미
# c: --create               create a new archive
# v: --verbose              verbosely list files processed
# f: --file=ARCHIVE         use archive file or device ARCHIVE

압축 해제

$ tar -xvf [file name]
# ex) tar -xvf abc.tar
# 옵션 의미
# e: --extract, --get       extract files from an archive

특정 폴더에 압축을 풀려면 "-C" 옵션으로 위치 설정

$ tar -xvf [file name] -C [out dir]

tar.gz

다음과 같이 파일을 압축하거나 풀 수 있습니다.

압축

$ tar -zcvf [output file name] [target] [target2] [...]
# ex) tar -zcvf abc.tar.gz ./folder1
# 옵션 의미
# z: --gzip, --gunzip, --ungzip   filter the archive through gzip

압축 해제

$ tar -zxvf [file name]
# ex) tar -zxvf abc.tar.gz

특정 폴더에 압축을 풀려면 "-C" 옵션으로 위치 설정

$ tar -zxvf [file name] -C [out dir]

tar.bz2

다음과 같이 파일을 압축하거나 풀 수 있습니다.

압축

$ tar -jcvf [output file name] [target] [target2] [...]
# ex) tar -jcvf abc.tar.bz2 ./folder1
# 옵션 의미
# -j, --bzip2                filter the archive through bzip2

압축 해제

$ tar -jxvf [file name]
# ex) tar -jxvf abc.tar.bz2

특정 폴더에 압축을 풀려면 "-C" 옵션으로 위치 설정

$ tar -zxvf [file name] -C [out dir]