How to unpack a ZIP file in the terminal with SSH (Ubuntu/Linux)

Marc Wagner, January 30, 2023

Uploa­ding indi­vi­du­al files can be a leng­thy pro­cess — espe­ci­al­ly if the ser­ver only allows a limi­t­ed num­ber of con­nec­tions. For­t­u­na­te­ly, the­re are other means and ways to get around the bot­t­len­eck.

Ins­tead of uploa­ding indi­vi­du­al files to your ser­ver, you can pack all files into an archi­ve (ZIP). Then just one con­nec­tion to the ser­ver is enough to upload the data with full band­width.

The ser­ver then does the unpack­ing for us. For this pur­po­se the­re is the packa­ge “unzip”.

Note: If the “unzip” packa­ge is not yet instal­led on your Ubun­tu ser­ver, you can do this with the fol­lo­wing com­mand:

sudo apt install unzip

For Cent­OS and Fedo­ra, use the fol­lo­wing com­mand:

sudo yum install unzip

After the instal­la­ti­on the “unzip” packa­ge is direct­ly available. The usa­ge is brief­ly docu­men­ted as fol­lows:

unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]

Below, I’d like to point out the most com­mon uses so you can get star­ted right away.

Simple unpacking #

If you want to unpack a file “file.zip”, you can do this with the fol­lo­wing ent­ry

unzip "datei.zip"

The files are unpa­cked into the cur­rent direc­to­ry.

Unpack to a predefined directory #

It is also pos­si­ble to spe­ci­fy that the files are unpa­cked to a spe­ci­fic direc­to­ry when unpack­ing. For this we extend the call by the para­me­ter “-d” and then spe­ci­fy into which direc­to­ry the files are to be unpa­cked.

unzip "datei.zip" -d /hier/verzeichnis/eintragen

Exclude files during unpacking #

You can use the fol­lo­wing com­mand to exclude indi­vi­du­al files during unpack­ing:

unzip "datei.zip" -x "datei-1.txt" -x "datei-2.txt" -x "datei-3.txt"

It is also pos­si­ble to exclude all files with a cer­tain file exten­si­on:

unzip "datei.zip" -x "*.png" -x "*.sql"

Also fol­ders can be com­ple­te­ly excluded during unpack­ing:

unzip "datei.zip" -x "folder1/*"

Conclusion #

Espe­ci­al­ly if you have a lot of files that you want to upload from your com­pu­ter to a ser­ver, you should use an archi­ve. In doing so, you save time, which allows you to speed up your work­flow signi­fi­cant­ly.

The SSH com­mands exe­cu­ted in this post will help you res­to­re back­ups and move con­tent wit­hout being rest­ric­ted by limi­t­ed ser­ver con­nec­tions.

Avatar of Marc Wagner
Marc Wagner

Hi Marc here. I'm the founder of Forge12 Interactive and have been passionate about building websites, online stores, applications and SaaS solutions for businesses for over 20 years. Before founding the company, I already worked in publicly listed companies and acquired all kinds of knowledge. Now I want to pass this knowledge on to my customers.

Similar Topics

Comments

Leave A Comment