Unzipping folder in linux

Unzip All Files In A Directory

I have a directory of ZIP files (created on a Windows machine). I can manually unzip them using unzip filename , but how can I unzip all the ZIP files in the current folder via the shell? Using Ubuntu Linux Server.

for windows in powershell: Get-ChildItem ‘path to folder’ -Filter *.zip | Expand-Archive -DestinationPath ‘path to extract’ -Force

17 Answers 17

This works in bash, according to this link:

Just put in some quotes to escape the wildcard:

+1 This one worked for me. I had to unzip filenames with a particular format while restricting the rest. I just kept the matching format within double quotes and it worked like charm. Output tells me the number of archives successfully processed.

The shell script below extracts all zip files in the current directory into new dirs with the filename of the zip file, i.e.:

./myfile1/files. ./myfile2/files. 

Shell script:

#!/bin/sh for zip in *.zip do dirname=`echo $zip | sed 's/\.zip$//'` if mkdir "$dirname" then if cd "$dirname" then unzip ../"$zip" cd .. # rm -f $zip # Uncomment to delete the original zip file else echo "Could not unpack $zip - cd failed" fi else echo "Could not unpack $zip - mkdir failed" fi done 
cd /dir/with/zips wget -O - https://www.toptal.com/developers/hastebin/suvefuxuxo.bash | bash 

the ` saved my day! thanks! I am doing some loop, unzip, perform an action, copy, grep something, remove. The thing missing was how to go from file.gz to file as a variable in the bash script

This should be the ultimate answer to all unzipping anywhere and anytime, why is this not the accepted answer? 🙂

unzip *.zip, or if they are in subfolders, then something like

find . -name "*.zip" -exec unzip <> \; 

Actually this will do exactly what is expected, the result of the find operation is being passed to unzip

This will extract all the zip files in current directory, what if I want the zip files (present in subfolders) to be extracted in the respective subfolders ?

Unzip all .zip files and store the content in a new folder with the same name and in the same folder as the .zip file:

find . -name '*.zip' -exec sh -c 'unzip -d "$" "$1"' _ <> \; 

This will extract all the zip files in current directory, what if I want the zip files (present in subfolders) to be extracted in the respective subfolders ?

for i in *.zip; do newdir="$" && mkdir "$newdir" unzip "$i" -d "$newdir" done 

This will unzip all the zip archives into new folders named with the filenames of the zip archives.

Читайте также:  Копирование разделов astra linux

a.zip b.zip c.zip will be unzipped into a b c folders respectively.

This one worked for my use case, needs more up votes. The other approaches do not place the extracted files in a folder of the same name, as expected, but there are some cases where using this approach to separate the folders will be needed.

In any POSIX shell, this will unzip into a different directory for each zip file:

for file in *.zip do directory="$" unzip "$file" -d "$directory" done 

aunpack -e *.zip , with atool installed. Has the advantage that it deals intelligently with errors, and always unpacks into subdirectories unless the zip contains only one file . Thus, there is no danger of polluting the current directory with masses of files, as there is with unzip on a zip with no directory structure.

aunpack -e -D *.zip if you want each zip to get its own output dir regardless of the number of files in it (similar to default behavior of ExtractAll in Windows)

for file in ‘ls *.zip’; do unzip «$» -d «$»; done

If by ‘current directory’ you mean the directory in which the zip file is, then I would use this command:

find . -name '*.zip' -execdir unzip <> \; 
-execdir command ; -execdir command <> + 

Like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find. This a much more secure method for invoking commands, as it avoids race conditions during resolution of the paths to the matched files. As with the -exec option, the ‘+’ form of -execdir will build a command line to process more than one matched file, but any given invocation of command will only list files that exist in the same subdirectory. If you use this option, you must ensure that your $PATH environment variable does not reference the current directory; otherwise, an attacker can run any commands they like by leaving an appropriately-named file in a directory in which you will run -execdir.

Источник

How to Unzip a Zip File in Linux [Beginner’s Tutorial]

This quick tip shows you how to unzip a file in Ubuntu and other Linux distributions. Both terminal and GUI methods have been discussed.

Zip is one of the most common and most popular ways to create compressed archive files. It is also one of the older archive file formats that were created in 1989. Since it is widely used, you’ll regularly come across a zip file. In an earlier tutorial, I showed how to zip a folder in Linux. In this quick tutorial for beginners, I’ll show you how to unzip files in Linux. Prerequisite: Verify if you have unzip installed In order to unzip a zip archive file, you must have the unzip package installed in your system. Most modern Linux distributions come with unzip support but there is no harm in verifying it to avoid bad surprises later. In a terminal, use the following command:

Читайте также:  Очистить линукс одной командой

If it gives you some details, you have unzip installed already. If you see an ‘unzip command not found’ error, you have to install. In Ubuntu and Debian based distributions, you can use the command below to install unzip.

Unzip files in Linux command line

Using unzip command in Linux is absolutely simple. In the directory, where you have the zip file, use this command:

You can also provide the path to the zip file instead of going to the directory. You’ll see extracted files in the output:

unzip metallic-container.zip -d my_zip Archive: metallic-container.zip inflating: my_zip/625993-PNZP34-678.jpg inflating: my_zip/License free.txt inflating: my_zip/License premium.txt

There is a slight problem with the above command. It will extract all the contents of the zip file in the current directory. That’s not a pretty thing to do because you’ll have a handful of files leaving the current directory unorganized.

Unzip to a specific directory

A good practice is to unzip to directory in Linux command line. This way, all the extracted files are stored in the directory you specified. If the directory doesn’t exist, it will create one.

unzip zipped_file.zip -d unzipped_directory

Now all the contents of the zipped_file.zip will be extracted to unzipped_directory.

Since we are discussing good practices, another tip you can use is to have a look at the content of the zip file without actually extracting it.

See the content of the zip file without unzipping it

You can check the content of the zip file without even extracting it with the option -l.

unzip -l metallic-container.zip Archive: metallic-container.zip Length Date Time Name --------- ---------- ----- ---- 6576010 2019-03-07 10:30 625993-PNZP34-678.jpg 1462 2019-03-07 13:39 License free.txt 1116 2019-03-07 13:39 License premium.txt --------- ------- 6578588 3 files

There are many other usage of the unzip command in Linux but I guess now you have enough knowledge to unzip files in Linux.

Unzip files in Linux using GUI

You don’t always have to go to the terminal if you are using desktop Linux. Let’s see how to unzip in Ubuntu Linux graphically. I am using GNOME desktop here with Ubuntu 18.04 but the process is pretty much the same in other desktop Linux distributions.

Open the file manager and go to the folder where your zip file is stored. Right click the file and you’ll see the option “extract here”. Select this one.

Unzip Files Ubuntu

Unlike the unzip command, the extract here options create a folder of the same name as the zipped file and all the content of the zipped files are extracted to this newly created folder. I am glad that this is the default behavior instead of extracting everything in the current directory.

Читайте также:  Linux mint разблокировка связки ключей отключить

There is also the option of ‘extract to’ and with that you can specify the folder where you want to extract the files.

That’s it. Now you know how to unzip a file in Linux. Perhaps you might also be interested in learning about using 7zip in Linux.

If you have questions or suggestions, do let me know in the comment section.

Источник

How to Zip and Unzip a directory and its files in Linux [duplicate]

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.

3 Answers 3

You say you are a newbie. Maybe you got Windows-experiences. If you do not have the packages installed yet, you need to

sudo apt-get install zip gzip tar 

first (or by a graphical pkg-manager).

Then, for an entry it would be the easiest way to use zip/unzip:

zip -r my_arch.zip my_folder 

Zip stores relative path names by default. There are several parameter-options available for zip. For that read: the manual (man zip). For a starting this will do.

Most often you will see .tar.gz endings in linux-world. That’s the product of two tools: TAR (the tape archiver) and GZIP (the GNU-Zip). Tar has got the call option to automatically gzip/gunzip files after «taring».

tar -cvzf may_arch.tar.gz my_folder 
  • -c means «create»
  • -v means «verbose» (sometimes bothersome and slowing down. )
  • -z means «use (GNU)zip»
  • -f XYZ declares the name of the output file. (You should chose a helping name like XYZ.tar.gz)

There may also be .tar.bz2 endings. This is the product of the -j parameter instead of the -z parameter: you will choose compression with BZIP2 (-> man bzip2).

To extract you simply use -x (eXtract) instead of -c (Create):

You can use the zip and unzip command line utilities. These can be installed by running

sudo apt-get install zip unzip 

I know several ways, but since you’re new on linux. So I’ll tell you how to zip a file using GUI method (the easiest way).

enter image description here

  1. Create a new folder and fill it with anything you want, for example many of file (In my case, I’ll fill it with theme folder) :

enter image description here

  1. Right click the folder you want to zip and select «Compress. » option : enter image description here
  2. You can choose which file format you want by clicking combobox next to «Filename» textbox. Also you can set the folder you want to zip location. enter image description here

enter image description here

Clicking «Other options» will lead you to password section, in other word you can set password for your preferred file so someone (include you) have to enter password before unzip the file.

Источник

Оцените статью
Adblock
detector