Compression Cheat Sheet¶
Single-file compressors¶
| Action |
gzip |
bzip2 |
xz |
zstd |
lz4 |
| Compress |
gzip f |
bzip2 f |
xz f |
zstd f |
lz4 f |
| Keep original |
-k |
-k |
-k |
default |
default |
| Remove original |
default |
default |
default |
--rm |
--rm |
| Decompress |
gunzip f.gz |
bunzip2 f.bz2 |
unxz f.xz |
unzstd f.zst |
unlz4 f.lz4 |
| To stdout |
zcat |
bzcat |
xzcat |
zstdcat |
lz4cat |
| Grep |
zgrep |
bzgrep |
xzgrep |
zstdgrep |
— |
| Page |
zless |
bzless |
xzless |
zstdless |
— |
| Diff |
zdiff |
bzdiff |
xzdiff |
— |
— |
| Test |
gzip -t |
bzip2 -t |
xz -t |
zstd -t |
lz4 -t |
| Info |
gzip -l |
— |
xz -l |
zstd -l |
— |
| Default level |
-6 |
-9 |
-6 |
-3 |
-1 |
| Max level |
-9 |
-9 |
-9e |
--ultra -22 |
-12 |
| Threads |
pigz |
lbzip2 |
-T0 |
-T0 |
— |
Also: lzip (lzip, -k, -d), brotli (brotli, -d, -q 11), lzop (lzop, -d), compress (gzip -d file.Z).
tar¶
| Action |
Command |
| Create plain |
tar cvf a.tar dir/ |
| Create gzip |
tar czvf a.tar.gz dir/ |
| Create bzip2 |
tar cjvf a.tar.bz2 dir/ |
| Create xz |
tar cJvf a.tar.xz dir/ |
| Create zstd |
tar --zstd -cvf a.tar.zst dir/ |
| Create by extension |
tar caf a.tar.zst dir/ |
| Custom compressor |
tar -I 'zstd -T0 -19' -cf a.tar.zst dir/ |
| Extract (auto-detect) |
tar xvf a.tar.* |
| Extract into dir |
tar xf a.tar.gz -C /dest |
| Extract one member |
tar xf a.tar.gz path/in/archive |
| Member to stdout |
tar xOf a.tar.gz path/in/archive |
| List |
tar tvf a.tar.* |
| Exclude |
tar czf a.tar.gz --exclude='*.log' dir/ |
| Contents without parent dir |
tar czf a.tar.gz -C dir . |
| Strip top dir |
tar xf a.tar.gz --strip-components=1 |
| Keep ACLs/xattrs |
tar --acls --xattrs -cpzf a.tar.gz dir/ |
zip and 7-Zip¶
| Action |
Command |
| Zip a dir |
zip -r a.zip dir/ |
| Unzip |
unzip a.zip / unzip a.zip -d dest/ |
| List zip |
unzip -l a.zip |
| Test zip |
unzip -t a.zip |
| Weak-encrypted zip |
zip -r -e a.zip dir/ |
| AES zip |
7z a -tzip -p -mem=AES256 a.zip dir/ |
| 7z archive |
7z a a.7z dir/ |
| 7z max |
7z a -mx=9 a.7z dir/ |
| 7z encrypted + hidden names |
7z a -p -mhe=on a.7z dir/ |
| Extract 7z |
7z x a.7z -odest |
| List 7z |
7z l a.7z |
| Extract RAR |
unrar x a.rar / 7z x a.rar / unar a.rar |
| Extract anything |
bsdtar -xf file / 7z x file / unar file |
cpio, ar, packages¶
| Action |
Command |
| Create cpio |
find . -print0 \| cpio --null -o -H newc > a.cpio |
| Extract cpio |
cpio -idmv < a.cpio |
| Unpack RPM |
rpm2cpio p.rpm \| cpio -idmv |
| Unpack .deb |
dpkg-deb -x p.deb out/ (or ar x p.deb) |
| SquashFS image |
mksquashfs dir/ img.sqsh -comp zstd |
| Extract SquashFS |
unsquashfs -d out/ img.sqsh |
Encryption¶
| Action |
Command |
| age (passphrase) |
tar cf - dir \| zstd \| age -p > d.tar.zst.age |
| age decrypt |
age -d d.tar.zst.age \| zstd -d \| tar xf - |
| age (public key) |
... \| age -r age1... > d.age |
| gpg symmetric |
gpg -c --cipher-algo AES256 file |
| gpg decrypt |
gpg -d file.gpg > file |
| openssl |
openssl enc -aes-256-cbc -salt -pbkdf2 -iter 600000 -in f -out f.enc |
| openssl decrypt |
openssl enc -d -aes-256-cbc -pbkdf2 -iter 600000 -in f.enc -out f |
Pipelines¶
| Action |
Command |
| Push tree over SSH |
tar cf - dir \| zstd -T0 \| ssh h 'zstd -d \| tar xf - -C /dest' |
| Progress |
tar cf - dir \| pv \| zstd -T0 > d.tar.zst |
| Split |
tar cf - dir \| zstd \| split -b 1G -d - d.tar.zst.part- |
| Rejoin |
cat d.tar.zst.part-* \| zstd -d \| tar xf - |
| Dump DB |
pg_dump db \| zstd -T0 > db.sql.zst |
| Identify a file |
file mystery.bin |
See also¶