How To Zip (Compress) and Unzip (Extract) Files

Monday, August 15th 2016. | how to

#howto ,#tutorial #VPS – How To Zip (Compress) and Unzip (Extract) Files – This tutorial explains step by step guide (with pics) about How To Zip (Compress) and Unzip (Extract) Files

Compressing several files and folders into a single distributable file is the most common way done by many computer users around the world. In Windows, you can simply use Winzip, WinRAR, 7Zip, and so on to zipping and unzipping file. If you’ve installed full Linux distros with GUI, you can also find and use similar app to do similar tasks. But what about a Linux server which you can only access it via SSH client? Realizing that many files are zipped and distributed as .zip file, also that you may need to zip several files into one .zip file so you can download it or transfer it elsewhere, so here it is I tell you how to do zipping and unzipping in a Linux-based VPS or Dedicated server via SSH client (in this case I use Putty, in Linux or Mac you can use Terminal).

Purpose:
I will show you how to zip / compress file and to unzip / decompress / extract file in Linux server via SSH

How to Unzip / extract File?

Step 1.
Open Putty or Terminal then login to your server via SSH

read: How to use Putty to SSH

Step 2.
Once you are logged into your server via SSH, now navigate to the directory where the .zip file you wish to unzip is located there.

read: How to navigate from one directory to another in SSH

example zip 1

Step 3.
Then type following command to try unzipping

unzip [filename].zip

example

unzip screenshot.zip

you may be successful but you may not.

error message:
– bash: unzip: command not found

In this case you have to install it first.

Step 4.
Use following command:

for Debian and Ubuntu:

apt-get install unzip

for Red Hat Linux/Fedora/CentOS users:

yum install unzip

Step 5.
That’s it. Now you can try unzipping it again using command in step 3 above.

example-zip-4-sukses-uznip

How to zip / compress file?

Step 1.
Open Putty or Terminal then login to your server via SSH

Step 2.
Once you are logged into your server via SSH, now navigate to the directory where the files and folders you wish to zip / compress are located there.

Step 3.
Use following command:

zip [zip file name] [file 1] [file 2] [file 3] [file and so on]

example:

zip example.zip 1.txt 2.txt 3.txt

In this example we’ll compress files 1.txt, 2.txt and 3.txt into a single example.zip file

example zip

you may be successful but you may not.

error message:
– bash: zip: command not found

In this case you have to install it first.

Step 4.
Use following command to install zip function:

for Debian and Ubuntu:

apt-get install zip

for Red Hat Linux/Fedora/CentOS users:

yum install zip

install zip

Step 5.
That’s it. Now you can try zipping it again using command in step 3 above.

FAQs

Q: How to zip all files in current directory?
A: use following command:

zip [zip file name] *

example

zip example2.zip *

example zip

p.s: Basically you don’t have to add .zip extension / suffix because the zip command will add this automatically. But we use .zip as suffix to make you understand easier regarding the command and to distinctive which file name should be the .zip name. Here’s another example

zip example4 *

output:

example zipping

Q: How to zip up an entire directory including all sub-directories
A: use this commane:

zip -r [zip file name] *

example:

zip -r picpic *

example zipping

Q: How to test a .zip file validity?
A: use this command:

unzip -tq [filename].zip

example:

unzip -tq picpic.zip

example unzip

Q: How to extract / unzip certain file from a .zip file?
A: use this command:

unzip [filename].zip [thefile]

example:

unzip picpic.zip 1.txt

unzip certain file

Q: How to list all files from a .zip file?
A: use this command:

unzip -l [filename].zip

example:

unzip -l picpic.zip

example unzip

Q: How to extract / unzip all files / folders into the certain directory?
A: use this command:

unzip [filename].zip -d /directoryname

example:

unzip picpic.zip -d /pictures

example unzip

That’s all most common the zipping and unzipping command you should know. All of those commands are pretty basic command and the most-used ones to manage .zip files. I thing mastering all of those is enough to be able to manage unmanaged VPS or Dedicated server. Especially for newbies..

This post How To Zip (Compress) and Unzip (Extract) Files is part of ServerMom.

Source link