Zip and unzip a directory and its file in linux [closed]
Asked Answered
C

3

8

I am a newbie in Linux. Whats is the complete process to zip and unzip a directory and its files? Please mention if any installation has to be done.

Courtneycourtrai answered 13/8, 2015 at 7:29 Comment(1)
sudo install gunzipRhody
G
12

To zip a folder and it's contents recursively:

zip -r archivefile foldername

To unzip a zip file:

unzip archivefile
Garlinda answered 13/8, 2015 at 7:35 Comment(3)
what is archivefile?Courtneycourtrai
@user5193454 it is the zip file. putting the .zip extension in the filename when running the commands is optional, as without it the command will append with .zip anyway :)Garlinda
you can unzip a file into a specific Folder by: unzip yourfile -d yourfolderBanzai
F
0

Several options exist, the most common ones:

On CLI (command line interface) there are the two utilities zip and unzip which do the obvious thing. For example to compress a directory "my-folder" with all its content using the zip algorithm you would do a zip -r my-folder.zip myfolder. To uncompress it your would use unzip my-folder.zip. Paths are always relative to the current working directory, so where you execute the command. Take a look at the "man page" to find out about the usage: man zip.

There are also GUI utilities (so utilities with a graphical user interface), but it depends on what desktop environment you use, since they are typically integrated. There is ark for KDE and a differente service menus that can be used for example in the file manager dolphin. There certainly are similar solutions for desktop environments like GNOME or Unity.

The question what packages you have to install depends a bit on the Linux distribution you use. The package names may vary slightly, but in general you certainly should be able to find the "zip" package in your local package management system.

Furtek answered 13/8, 2015 at 7:35 Comment(2)
Do i have to install zip and unzip commands first?Courtneycourtrai
@user5193454 Sure, to use a CLI command it has to be installed. It is usually already contained in a typical installation of a desktop GNU/Linux distribution. But you can easily check that. Just give it a try. If you get an error about an "unknown command", then obviously it is not installed (or misstyped...). Or have a try with which zip or whereis zip. If you get a result, that is where the utility is installed. Or, slower but also interesting, you simply check inside your local package management system if it is installed.Furtek
W
0

I had alot of trouble using unzip giving me errors like

sql.zip has more than one entry--rest ignored

Etc.

Using php worked like a sharm. Oneliner:

php -r '$zip = new ZipArchive; $zip->open("db.sql.zip"); $zip->extractTo("./"); $zip->close(); echo "Yay!";'

Run in cmd / terminal after php is installed

Winsome answered 9/2, 2018 at 13:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.