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

Uploading individual files can be a lengthy process – especially if the server only allows a limited number of connections. Fortunately, there are other means and ways to get around the bottleneck.

Instead of uploading individual files to your server, you can pack all files into an archive (ZIP). Then just one connection to the server is enough to upload the data with full bandwidth.

The server then does the unpacking for us. For this purpose there is the package “unzip”.

Note: If the “unzip” package is not yet installed on your Ubuntu server, you can do this with the following command:

sudo apt install unzip

For CentOS and Fedora, use the following command:

sudo yum install unzip

After the installation the “unzip” package is directly available. The usage is briefly documented as follows:

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

Below, I’d like to point out the most common uses so you can get started right away.

Simple unpacking #

If you want to unpack a file “file.zip”, you can do this with the following entry

unzip "datei.zip"

The files are unpacked into the current directory.

Unpack to a predefined directory #

It is also possible to specify that the files are unpacked to a specific directory when unpacking. For this we extend the call by the parameter “-d” and then specify into which directory the files are to be unpacked.

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

Exclude files during unpacking #

You can use the following command to exclude individual files during unpacking:

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

It is also possible to exclude all files with a certain file extension:

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

Also folders can be completely excluded during unpacking:

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

Conclusion #

Especially if you have a lot of files that you want to upload from your computer to a server, you should use an archive. In doing so, you save time, which allows you to speed up your workflow significantly.

The SSH commands executed in this post will help you restore backups and move content without being restricted by limited server connections.

Hier klicken, um den Beitrag zu bewerten
[Gesamt: 0 Durchschnitt: 0]

Leave A Comment

Title