Archives: tar, gzip, zip
Creating and extracting tar.gz and zip, viewing contents, streaming over SSH.
tar
Create a tar.gz archive
tar -czf <archive>.tar.gz <path>
Extract a tar.gz archive
tar -xzf <archive>.tar.gz
Extract into a specific directory
tar -xzf <archive>.tar.gz -C <destination>
List archive contents
tar -tzf <archive>.tar.gz
Create an archive excluding folders
tar -czf <archive>.tar.gz --exclude=node_modules --exclude=.git <path>
Extract a single fileadvanced
tar -xzf <archive>.tar.gz path/inside/archive.txt
Better compression with zstdadvanced
tar --zstd -cf <archive>.tar.zst <path>
gzip
Compress a file (replaces it with .gz)
gzip <file>
Decompress
gunzip <file>.gz
Read a compressed log without extracting
zcat <file>.gz | less
Search inside compressed files
zgrep '<pattern>' <file>.gz
zip
Zip a directory
zip -r <archive>.zip <path>
Unzip into a directory
unzip <archive>.zip -d <destination>
List zip contents
unzip -l <archive>.zip
Over the network
Copy a directory to a server as a streamadvanced
tar -czf - <path> | ssh <user>@<host> 'tar -xzf - -C /tmp'
Download and extract in one goadvanced
curl -L <url> | tar -xz