Archive & Compression
Create, extract, and manage compressed archives. Cross-platform (macOS, Linux).
tar + gzip (.tar.gz / .tgz)
Create:
code
exec: tar -czf /path/to/archive.tar.gz -C /path/to/parent directory_name
Extract:
code
exec: tar -xzf /path/to/archive.tar.gz -C /path/to/destination
List contents:
code
exec: tar -tzf /path/to/archive.tar.gz
tar + bzip2 (.tar.bz2)
Create:
code
exec: tar -cjf /path/to/archive.tar.bz2 -C /path/to/parent directory_name
Extract:
code
exec: tar -xjf /path/to/archive.tar.bz2 -C /path/to/destination
tar + xz (.tar.xz) — best compression ratio
Create:
code
exec: tar -cJf /path/to/archive.tar.xz -C /path/to/parent directory_name
Extract:
code
exec: tar -xJf /path/to/archive.tar.xz -C /path/to/destination
zip (.zip)
Create:
code
exec: zip -r /path/to/archive.zip /path/to/directory
Extract:
code
exec: unzip /path/to/archive.zip -d /path/to/destination
List contents:
code
exec: unzip -l /path/to/archive.zip
Add files to existing zip:
code
exec: zip -g /path/to/archive.zip /path/to/newfile.txt
Create with password:
code
exec: zip -e -r /path/to/secure.zip /path/to/directory
gzip (single file)
Compress:
code
exec: gzip /path/to/file.txt
Decompress:
code
exec: gunzip /path/to/file.txt.gz
Keep original:
code
exec: gzip -k /path/to/file.txt
7-Zip (.7z) — requires p7zip
Create:
code
exec: 7z a /path/to/archive.7z /path/to/directory
Extract:
code
exec: 7z x /path/to/archive.7z -o/path/to/destination
List:
code
exec: 7z l /path/to/archive.7z
Inspect Any Archive
File type detection:
code
exec: file /path/to/archive
Exclude Patterns
Tar with exclusions:
code
exec: tar -czf /path/to/archive.tar.gz --exclude='*.log' --exclude='node_modules' -C /path/to/parent directory_name
Zip with exclusions:
code
exec: zip -r /path/to/archive.zip /path/to/directory -x "*.log" "*/node_modules/*"
Split Large Archives
Create split archive (100MB parts):
code
exec: tar -czf - /path/to/large_dir | split -b 100m - /path/to/archive.tar.gz.part
Reassemble and extract:
code
exec: cat /path/to/archive.tar.gz.part* | tar -xzf - -C /path/to/destination
Compare Archive Contents
code
exec: diff <(tar -tzf archive1.tar.gz | sort) <(tar -tzf archive2.tar.gz | sort)
Notes
- •
tar,gzip,zip/unzipare pre-installed on macOS and most Linux distros. - •
xzoffers the best compression ratio but is slower. - •
7zneedsp7ziporp7zip-full(install viabrew install p7ziporapt install p7zip-full). - •Use
-Cwith tar to control the base directory in the archive. - •For Windows compatibility,
.zipis the safest format.