unzip / untar one specific file or (sub)folder
I have an ubuntu VPS which only has terminal SSH connection. I just started linux (ubuntu) and I am even writing scripts now.
But now I am hitting a wall again on the un-TAR and un-ZIP subject. Normal unzip/untar actions go in the correct way, but this is when everything needs to be extracted. But when I only want to extract only 1 specific file or folder (or subfolder) I always end up extracting all the content in it's original path. (which is normal behaviour if the archive is created with full path settings). I read all the man pages about "unzip" and "TAR" I only got to this command, which seemed to work: Code:
tar -x modsecurity-crs_2.2.1/util/rules-updater.pl -zf modsecurity-crs_2.2.1.tar - C /root/somedir/modsec-tar/ --strip-components=2 When I use directory that does not exist (red highilghted), the specific file gets unpacked in the directory where run the extract command. The same goes if I use a directory that exists (red highlighted). I could replace ".../util/rules-updater.pl" with the following: ".../util/*" which would extract everything under "util". For the TAR command at least I have something that seems to work, for the unzip command I really do not have any idea how to approach this. All the tutorials I read always comes down to form like this: Code:
unzip <filename>.zip If someone could provide an example for extracting 1 single specific directory from a TAR and ZIP to a specified folder, that would mean a lot to me. I read the man pages, searched google and searched here. (if there is a script which has the same approach, that would be welcome to) |
unzip -d /path/to/directory myZip.zip
try Code:
man unzip |
If try that, like this:
unzip -d /util/ modsecurity-crs_2.2.1.zip It unpacks everything in the directory /util/ (which is located in the root) What I want is to extract one specified folder wihtin the zip archive. In other words: What I want is an extraction of the directory "util" in the zip archive "unzip -d /util/ modsecurity-crs_2.2.1.zip" to a specified directory of my choice. I did read the man pages about unzip, but that didn't get me any further. |
http://kent.dl.sourceforge.net/proje...s_2.2.1.tar.gz
> modsecurity-crs_2.2.1.tar.gz : 382 kB. tar xvf modsecurity-crs_2.2.1.tar.gz : No options to extract one particular folder. Just delete the unwanted files. . |
@knudfl
Then I guess that also goes for the zip (unzip). That makes things a lot more clear. If it's not possible to extract single files/folders from a zip archive then I indeed have to extract the full archive and delete unwanted ones. Ok thanks! |
try something like
unzip -L yourZip.zip from this list choose which folder you want to extract then unzip yourZip.zip <dir that you want> -d <target folder> does it work? |
@nicolasdiogo
Your command worked! But I used the lower "l" not capital "L" switch -l list files (short format) -L make (some) names lowercase But this command you provided, helped: Code:
unzip yourZip.zip <dir that you want> -d <target folder> Code:
unzip modsecurity-crs_2.2.1.zip util/* -d /root/scripttest/test2 Code:
caution: filename not matched: util/regression_tests Thank you nicolasdiogo!!!! |
you are welcome
help others by closing the thread |
Quote:
It should be closed now. Thanks everyone! |
All times are GMT -5. The time now is 07:54 PM. |