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

Marc Wag­ner

Decem­ber 13, 2022

2 min read|

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.

88e86fcb816eff22bc917094df2862d8dd5c0e978b333e6dd5f36f808990c261 96

Arti­kel von:

Marc Wag­ner

Hi Marc here. I’m the foun­der of Forge12 Inter­ac­ti­ve and have been pas­sio­na­te about buil­ding web­sites, online stores, appli­ca­ti­ons and SaaS solu­ti­ons for busi­nesses for over 20 years. Befo­re foun­ding the com­pa­ny, I alre­a­dy work­ed in publicly lis­ted com­pa­nies and acqui­red all kinds of know­ledge. Now I want to pass this know­ledge on to my cus­to­mers.

Hast du eine Fra­ge? Hin­ter­lass bit­te einen Kom­men­tar