ajhsu / blog

The external storage of my brain.
3 stars 0 forks source link

Tar and Gzip command #57

Open ajhsu opened 6 years ago

ajhsu commented 6 years ago

Tar

Tar Options

-x: Extract
-f: File Name
-v: Verbose
-c: Create (To archive)
-t: List

Basic Usages

List all files verbosely

tar -tvf backup.tar

Archive into one single file

tar -cvf archive.tar foo bar

Equivalent with standard output

tar -cv foo bar > archive.tar

Extract an archive file

tar -xvf backup.tar

Gzip

Basic Usages

Compress a file

gzip file.txt

Note: This command will replace the original file.

Equivalent with standard output

cat file.txt | gzip > file.txt.gz

Decompress a file

gzip -d file.txt.gz

Note: This command will replace the original file.

Comression level

gzip -N / --fast / --best

Regulate the speed of compression using the specified digit N, where -1 or --fast indicates the fastest compression method (less compression) and -9 or --best indicates the slowest compression method (best compression).

The default compression level is -6 (that is, biased towards high compression at expense of speed).

Archive files with compression

Tar archiving is often used together with a compression method, such as gzip, to create a compressed archive.

400px-targzip svg (Source: https://en.wikipedia.org/wiki/Tar_(computing))

Compress an Archive using Gzip

tar -cvzf ~/backup-archive.tar.gz ~/backup/

Compress an Archive using Bzip2 and Xzip Compression

Bzip2 with -j

tar -cjf ~/backup-archive.tar.bz2 ~/backup/

xzip with -J tar -cvJf ~/backup-archive.tar.xz ~/backup/

Accessing gzipped files

Gzip with multi-process

Materials