All notes
Compress

Summary / Comparisons

This compared gzip, bzip2, and 7-zip/lzma.

zip

Usually -1 is best choice since it reduces time a lot without compromising too much capability in compression ratio.

-1, --fast.
-6, default.
-9, --best. Slowest, but smallest.
As shown by this survey, -1 is usually enough for a fastest speed by compromising only a little compression efficiency.

For a multi-core machine, pigz is better than normal zip since it computes parallelly.

# -q, --quiet
# -r, --recurse-paths
# -y, --symlinks. Keep symlinks.
# -x. Exclude .git directory.
zip -qry proj.zip proj -x *.git*

# -T, --test. Test the integrity of the new zip file. If the check fails, the old zip file is unchanged and (with the -m option) no input files are removed.

Zip related commands

unzip a.zip -d destDir # Extract the zip file to destDir.
unzip -t z.zip # Unzip to memory and test the fidelity of its CRC.
zip -R zipFile files # Recursively zip the files into zipFile.

# For 7za, you need to manually install p7zip on CentOS.
7za x file.7z -odir # Extract files with full paths to dir.
# Extract without using directory names. Don't use this!
# Because it will extract all files from all (sub)directories
# and put them under output directory!
7za e file.7z -odir
7za t file.7z # Test integrity.
7za l file.7z # List contents.

pigz -f -1 -p 4 -S .zip -k -K srcFileName;

tar

# -C, --directory=DIR. change to directory DIR
# tar ~/webapps/a/b/plugins/apps/ into ~/app.tar.gz.
# tar will use ./apps as relative path.
tar -czf ~/app.tar.gz -C ~/webapps/a/b/plugins apps

tar -xJf a.tar.xz # LZMA2 zipped.

# -p, --preserve-permissions, --same-permissions
tar -p

# The tar command should preserve symbolic links by default.