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
- Create a tarball:
tar -czvf archive.tar.gz /path/to/dir
- Extract:
tar -xzvf archive.tar.gz
- Create a zip:
zip -r archive.zip /path/to/dir
- Extract zip:
unzip archive.zip
Tips
tarflags:c=create,x=extract,z=gzip,v=verbose,f=file.- Use
pigzwithtarfor parallel gzip compression. - Exclude patterns with
--excludein tar.
Common issues
- Absolute paths: tar strips leading
/by default for safety. - Large archives: split into volumes with
splitif needed.