KandZ – Tuts

We like to help…!

Linux CLI 39 🐧 tar and zip commands

a - tar command

tar command is a tool for creating and manipulating archive files
It can pack multiple files into a single file and even compress them
You can also list the files in the archive and of course to extract them
Common options: c → create and archive from files and/or directories
x → extract an archive t → list the contents for an archive
v → verbose mode showing details r → updates or add files to an archive
W → verifies the integrity of an archive z → uses gzip compression
A → concatenates multiple archive files into a single file


b - tar command examples

tar -cvf files.tar 1.txt 2.txt → Creates an Archive
tar -tf files.tar → Lists Contents of an Archive
tar -xvf files.tar → Extract Files from an Archive
tar -cvfz files.tar.gz 1.txt 2.txt → creates a compressed tarball with gzip
tar -xvfz files.tar.gz → extracts a compressed tarball with gzip
tar -cvfj files.tar.bz2 1.txt 2.txt → creates a compressed tarball with bzip2
tar -xvfj files.tar.bz2 → extracts a compressed tarball with bzip2


c - zip command

zip command is used to compress and package files
It can pack multiple files and directories
The extension of the archive file is .zip
zip -r 1.zip 1/ → creates a Zip archive (-r → recursive)
zipinfo 1.zip → list content of a Zip Archive
unzip -v 1.zip → extract files from an archive (-v → verbose)
zip -r -1 output.zip / → creates the compression and setting the compression level(-1)
0-9 are the compression levels, default is 6
--encrypt → adds a password to the archive

Leave a Reply