Shell Cheatsheet - tar / zip
tar
x
: extractz
: compress archive using gzip programj
: bzip2c
: create archivev
: verbosef
: archive file name
.tar
No compression.
# Create
$ tar -cvf archive_name.tar directory_to_compress
# Extract the archive
$ tar -xvf archive_name.tar.gz
# Extract the files to a different directory
$ tar -xvf archive_name.tar -C /tmp/extract_here/
.tar.gz
# Create and compress
$ tar -cvzf archive_name.tar.gz directory_to_compress
# Decompress and extract
$ tar -xvzf archive_name.tar.gz
# Extract the files to a different directory:
$ tar -xvzf archive_name.tar.gz -C /tmp/extract_here/
.tar.bz2
# Create
$ tar -jcvf archive_name.tar.bz2 directory_to_compress
# Extract
$ tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/
pigz
pigz is a parallel version of gzip. Although it only uses a single thread for decompression, it starts 3 additional threads for reading, writing, and check calculation.
$ pigz -dc archive.tar.gz | tar xf -
# or
$ tar -I pigz -xvf archive.tar.gz
-I
is equivalent to --use-compress-program
.
zip
Compress
$ zip -r archive_name.zip directory_to_compress
Extract:
$ unzip archive_name.zip
Trouble Shooting
Error
$ unzip *.zip
error: caution: filename not matched:
Solution
$ unzip \*.zip