Saturday, June 20, 2015

How to Unzip / Zip file in Centos 6

Hello again, now i want to share how to zip and unzip file in centos, what in zip file? zipping file is collecting a few or more file that you choose and compress it into one file, so you can give that file or send to your friend or send it to file hosting, zip file usually used when you want to backup something, as a sample, i have website that i put on /public_html folder, and i want to back it up in case something happened or maybe you want to do a major change to your website, so i just zip my /public_html directory into one file, and i start change or modify the original file, if something happened, i just recover all my files in /public_html directory by unzipping from zip file that i created as backup.

Before we start, make sure zip package is installed in your system, by type zip in your terminal.
zip

if there are no zip package installed, it will reply -bash: zip: command not found
so you must install it first by type :

yum -y install zip

1. Zip
Now you have zip package installed in your system, now type zip, there are a lot of option for zip, we don't use that all, i usually only use -r and -v.
-r is recurse into directories it means, zip include directory
-v is verbose it will showing line by line what file has been added to your zip file

the command fo zip is

zip [options] [new_file_name.zip] [dir / file(s) that we want to zip]

example :
i want to zip files with .txt as extension
zip -v /home/backup/backup_mytext.zip /home/tutorial/*.txt

i want to backup my website file in /html/wordpress into /home/backup/
cd /var/www/html/wordpress/
zip -rv /home/backup/backup_myweb_15062015.zip *

2. Unzip
Before using unzip, try type
unzip

if the reply is -bash: unzip: command not found it mean there are no unzip package in your system, so you must install it first by type
yum -y install unzip

Now unzip package already installed in your system, lets start
To view file in .zip, use this command
unzip -l /home/backup/backup_myweb_15062015.zip

To restore / extract zip file, use this command
unzip /home/backup/backup_myweb_15062015.zip -d /var/www/home/html/wordpress

To restore / extract zip file, and overwrite it
unzip -o /home/backup/backup_myweb_15062015.zip -d /var/www/home/html/wordpress

To restore / extract zip file, and update it
unzip -u /home/backup/backup_myweb_15062015.zip -d /var/www/home/html/wordpress

There are a lot of options to use, but not all of that options is used, it depends on your case, maybe you will use it, but these are a basic command in compress and extract file(s)

0 comments:

Post a Comment