Linux zip extract to directory

How to extract only a specific folder from a zipped archive to a given directory?

If you get ‘caution: filename not matched: ‘/dir1/dir2/*’ when you try to extract something like ‘/dir1/dir2/*’ — remove first ‘/’ from the path, so it becomes ‘dir1/dir2/*’. Double-check the existence of the path if this won’t work.

unzip /path/to/archive.zip 'in/archive/folder/*' -d /path/to/unzip/to 

did this? I get caution: filename not matched: foldername/\* when I run unzip $repozip «$2-master/\*» -d /srv/www/magento/ where $2 is the folder name in the zip I want to pull all the files and folders out of

Is there a way to extract contents of «in/archive/folder/*» that does not preserve path «in/archive/folder/»? I end up using mv afterwards to get files where I needed them.

-j strips all path info, and all files go into the target folder. Is there a way to remove only the common part of the path? Akin to zip -r .

The existing two answers are both correct, but it’s a bit tricky to specify the target directory, that should be better clarified.

Let’s say /target/root/ is the target dir upon the original unzip action, e.g.:

unzip -qq src.zip -d "/target/root/" 

Then, we need to use the same /target/root/ as the target dir afterward even though we want to extract only a specific sub-directory, as the way unzip works:

unzip -qq src.zip "sub/dir/*" "/target/root/" 

After all, the rule is actually simple, use the same target root directory for the -d option.

BTW, the -qq option is for unzip to be really quiet, feel free to remove it.

FYI: I did unzip -qq 2.3.zip "magento2-2.3/vendor/*" "vendor/" and got caution: filename not matched: vendor/`. This is on an ubuntu install in bash. I rarely unzip, probably did something else wrong.

Читайте также:  Linux ide code blocks

For me this unzipped the files in that specific directory, but did not pick up subdirectories; is that a different command?

The first time I read this I couldn’t make any sense of it at all. Then I read it a second time and I thought I understood it. Then I read it a third time and got a different meaning. Your answer should be [better] clarified. … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … Also, you refer to “the original unzip action”. What makes you think that there was a previous unzip action? What if I want to look at data for April 2017, so I download 2017.zip from the server and I want to extract the April folder (and nothing else)?

Источник

How to Create and Extract Zip Files to Specific Directory in Linux

In one of our several articles about the tar command, we showed you how to extract tar files to a specific or different directory in Linux. This short guide explains to you how to extract/unzip .zip archive files to a specific or different directory in Linux.

Zip is a simple, cross-platform file packaging and compression utility for Unix-like systems including Linux and Windows OS; plus many other operating systems. The “zip” format is a common archiving file format used on Windows PC’s and most importantly, it enables you to specify the compression level between 1 and 9 as an option.

Create Zip Archive File in Linux

To create a .zip (packaged and compressed) file from the command line, you can run a similar command like the one below, The -r flag enables recursive reading of files directory structure.

$ zip -r tecmint_files.zip tecmint_files

Create Zip File in Linux

To unzip the tecmint_files.zip archive file you have just created above, you can run the unzip command as follows.

The above command will extract the files into the current working directory. What if you want to send the unzipped files into a specific or different directory – you can learn this in the next section.

Читайте также:  Oracle linux server release

Extract Zip File to Specific or Different Directory

To extract/unzip .zip archive files to specific or different directory from the command line, include the -d unzip command flag as shown below. We will use the same example above to demonstrate this.

This will extract the .zip file content into the /tmp directory:

$ mkdir -p /tmp/unziped $ unzip tecmint_files.zip -d /tmp/unziped $ ls -l /tmp/unziped/

Extract Zip Files to Specific Directory

For more usage information, read zip and unzip command man pages.

You may also like to read the following related articles.

In this short article, we have explained how to extract/unzip .zip archive files to a specific or different directory in Linux. You can add your thoughts to this article via the feedback form below.

Источник

How to extract a zip file to a specific folder?

I have a zip file that I need to extract into another folder. When I set up extraction to said folder it says «permission denied». I’ve read here how to log into a terminal as root and superuser but can’t find anything to help me. I need to extract a file from my Downloads directory to /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins . Please explain how to extract a zip file to the correct folder.

yes the extension is .zip im trying to extract the zip file to plex media server plug ins . its in my downloads folder but when i try and extract to new directory it says i dont have permission

var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins to be exact is where i want it to go

2 Answers 2

We’ll extract to a different folder to be sure that permissions aren’t in our way:

  1. Open a terminal ( Ctrl + Alt + T should work).
  2. Now create a temporary folder to extract the file:
mkdir temp_for_zip_extract 
unzip /path/to/file.zip -d temp_for_zip_extract 

You should now have the contents of your zip file temp_for_zip_extract and can copy them into the desired folder.

If you can’t copy the files to your folder, then check the permissions on your target folder.

The path to the downloads folder depends on what you used to download it to, try ~/Downloads . If you can’t find it, then try this in a terminal:

cd ~; find -name 'filename.zip' 

You can also use a file manager, of course. There is Nautilus, Nemo, Thunar and many more, depending on your environment. Start the file manager and double click on your zip file, just like you would do in Windows.

Источник

Create a dedicated folder for every zip files in a directory and extract zip files

If I choose a zip file and right click «extract here» a folder with the zip filename is created and the entire content of the zip file is extracted into it. However, I would like to convert several zip files via shell. But when I do

the folder «filename» is not created but all the files are extracted into the current directory. I have looked at the parameters but there is no such parameter. I also tried

for zipfile in \*.zip; do mkdir $zipfile; unzip $zipfile -d $zipfile/; done 
for zipfile in \*.zip; do mkdir sed 's/\.zip//i' $zipfile; unzip $zipfile -d sed 's/\.zip//i' $zipfile/; done 

it is not working. How do I replace the .zip extension of $zipfile properly? Is there an easier way than a shell script?

7 Answers 7

unzip file.zip -d xxx will extract files to directory xxx, and xxx will be created if it is not there. You can check the man page for details.

The awk line below should do the job:

See the test below,

note that I removed |sh at the end, since my zips are fake archives; I just want to show the generated command line here.

kent$ ls -l total 0 -rw-r--r-- 1 kent kent 0 Nov 12 23:10 001.zip -rw-r--r-- 1 kent kent 0 Nov 12 23:10 002.zip -rw-r--r-- 1 kent kent 0 Nov 12 23:10 003.zip -rw-r--r-- 1 kent kent 0 Nov 12 23:10 004.zip -rw-r--r-- 1 kent kent 0 Nov 12 23:10 005.zip -rw-r--r-- 1 kent kent 0 Nov 12 23:10 006.zip -rw-r--r-- 1 kent kent 0 Nov 12 23:10 007.zip kent$ ls *.zip|awk -F'.zip' '' unzip 001.zip -d 001 unzip 002.zip -d 002 unzip 003.zip -d 003 unzip 004.zip -d 004 unzip 005.zip -d 005 unzip 006.zip -d 006 unzip 007.zip -d 007 

Источник

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