How to use tar gzip and zip for archiving

· Category: Linux

Short answer

Use tar for Unix-style archives and zip for cross-platform compatibility.

Steps

  1. Create a tarball:
tar -czvf archive.tar.gz /path/to/dir
  1. Extract:
tar -xzvf archive.tar.gz
  1. Create a zip:
zip -r archive.zip /path/to/dir
  1. Extract zip:
unzip archive.zip

Tips

  • tar flags: c=create, x=extract, z=gzip, v=verbose, f=file.
  • Use pigz with tar for parallel gzip compression.
  • Exclude patterns with --exclude in tar.

Common issues

  • Absolute paths: tar strips leading / by default for safety.
  • Large archives: split into volumes with split if needed.