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:
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
But the part in red
is a directory that does not exist and even than the command seems to work, this is not correct behaviour. And I could not get any info about "--strip-components".
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:
But I want to target a specific file/folder in the zip archive and extract that file/folder to directory specified by me.
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)