Compress & Extract a Folder
Compress a folder with tar.gz
tar czf backups/20191010-111100.tar.gz public_html
# Or create date dynamic
tar czf backups/$(date +%Y%m%d-%H%M%S).tar.gz public_html
c: Creates a new .tar archive file
z: Filter archive through gzip
f: File name type of the archive file
Compress a folder with tar.bz2
tar -cvjSf backups/backup_20191110.tar.bz2 public_html
c: Creates a new .tar archive file
v: Show the .tar file progress
j: Filter archive with bzip2
S: Handle sparse files efficiently
f: File name type of the archive file
Compress a folder with zip
zip -r backups/files_backup_20191010.zip public_html
Possible to zip with password:
zip -er backups/files_backup_20191010.zip public_html
e : enables encryption for your zip file.
Extract tar.gz file:
tar -xvzf 20191010-111100.tar.gz
x: Extract a archive file
v: Show the .tar file progress
z: Filter archive through gzip
f : Archive filename
Extract tar.bz2 file:
tar -xvjf backup_20191110.tar.bz2
# With destination folder
tar -xvjf backup_20191110.tar.bz2 -C /target/directory/
Unzip the zip file:
unzip files_backup_20191010.zip
#or
unzip files_backup_20191010.zip -d destination_folder
Notice: On the command line, it’s possible to use help commands to see available commands and simply use it.
Examples: “tar –help”, “zip –help”, “unzip –help”