Zip & unzip tar gunzip commands explained
apt install zip
apt install unzip
zip archive.zip file
zip archive.zip folder1 file2 file3
Directory and sub directories
zip -r bak.zip directory
zip -r bak.zip directorypath
zip path/bak.zip path/directory
zip -r /var/www/bak.zip /var/www/html
Compression level 0-9
zip -9 -r archivename.zip directory_name
Compression with password
zip -e archivename.zip directory_name
Password
Confirm password
Compress data in multiple files with size limit
zip -s 1g -r archivename.zip directory
1gb each
Zip all current directory
zip archivename *
Zio hidden files
zip archive.zip .* *
Zip only specific extensions
zip archive.zip *.html
Unzip
unzip archive.zip
-q supress output screenprinting
unzip to different directory
sudo unzip latest.zip -d /var/www
Unzip password protected files
unzip -P PasswOrd filename.zip
unzip -P filename.zip
Enter password
Confirm password
Tar
tarball, or tar, gzip, and bzip in Linux
Extract a tar.gz archive
tar -xvzf bigfile.tar.gz
x – Extract files
v – Verbose, print
z – file is a “gzipped” file
f – Use the following tar archive for the operation
specific directory or path
tar -xvzf bigfile.tar.gz -C /folder/subfolder/
-c parameter helps to directory path
gzip extraction
single file
tar -xz -f wp.tar.gz “./new/one.txt”
Multiple
tar -xv -f wordpress.tar.gz “./new/two.php” “./new/three.html”
Wildcard
tar -xv -f wordpress.tar.gz –wildcards “*.php”
Gzip View files without extraction using -t
tar -tz -f abc.tar.gz
Grep/ less
tar -tvz -f wordpress.tar.gz | grep wp-config.php
Create a tar/tar.gz archive
without compression
tar -cvf files.tar ./latest/
Z=gzip j=bzip, bz2 algorithm
With compression
tar -cvzf files.tar ./latest/
Add files to existing compress ed archives
Use gunzip to uncompress the tar and then add
using the “r” option it adds files to existing archives, without the creation of a new one
gunzip college.tar.gz
tar -rf college.tar ./tech/top.ppt
# gzip college.tar
ls
College.tar.gz