unzip -d option to extract file from jar to specific directory - linux

unzip -d option to extract file from jar to specific directory
Without using any option we can unzip specific file to same directory structure, but -d option doesn't seem to work.
unzip someNiceOne.jar com/some/comp/some/dir/name.properties
This will unzip file 'name.properties' to 'com/some/comp/some/dir/'.
I need 'name.properties' to be under same directory level where my jar is present, but -d option doesn't seem to work. Any alternative option?.
unzip -d option help :
-d extract files into exdir

Using -j option should do what you need.
-j junk paths (do not make directories)
In your case:
unzip -j someNiceOne.jar com/some/comp/some/dir/name.properties

Related

unzip file into same directory in linux

Example:
Here's list of files in "/tmp/test_dir"
file1
zip -r Test_Files.zip *
When I unzip Test_Files.zip I'm getting the below output
Current working directory "/tmp/test_dir"
/tmp/test_dir/file1
What I'm expecting when I unzip Test_Files.zip;
/tmp/test_dir/Test_Files/file1
Can anyone help how do i get expected result as mentioned above?
Use unzip. You can use -o to overwrite the existing files and -q to make it quiet. In doubt? Just use terminal and type in unzip (or try /usr/bin/unzip) to see helpful information.

How can I download all the files from a remote directory to my local directory?

I want to download all the files in a specific directory of my site.
Let's say I have 3 files in my remote SFTP directory
www.site.com/files/phone/2017-09-19-20-39-15
a.txt
b.txt
c.txt
My goal is to create a local folder on my desktop with ONLY those downloaded files. No parents files or parents directory needed. I am trying to get the clean report.
I've tried
wget -m --no-parent -l1 -nH -P ~/Desktop/phone/ www.site.com/files/phone/2017-09-19-20-39-15 --reject=index.html* -e robots=off
I got
I want to get
How do I tweak my wget command to get something like that?
Should I use anything else other than wget ?
Ihue,
Taking a shell programatic perspective I would recommend you try the following command line script, note I also added the citation so you can see the original threads.
wget -r -P ~/Desktop/phone/ -A txt www.site.com/files/phone/2017-09-19-20-39-15 --reject=index.html* -e robots=off
-r enables recursive retrieval. See Recursive Download for more information.
-P sets the directory prefix where all files and directories are saved to.
-A sets a whitelist for retrieving only certain file types. Strings and patterns are accepted, and both can be used in a comma separated list. See Types of Files for more information.
Ref: #don-joey
https://askubuntu.com/questions/373047/i-used-wget-to-download-html-files-where-are-the-images-in-the-file-stored

How to winzip a folder exclude parent folders?

I am using this command to winzip a folder, but "bldforge_AOMS_DEV\WebSphere_AVOB" is included in the zip.
winzip32.exe -min -a -r -p C:\Build\AOM.zip m:\bldforge_AOMS_DEV\WebSphere_AVOB*
How can I create the zip without "bldforge_AOMS_DEV\WebSphere_AVOB", just all the files under bldforge_AOMS_DEV\WebSphere_AVOB\?
Thanks
Jirong
I'm no expert by i think this might solve you problem
winzip32.exe -min -a -r -p C:\Build\AOM.zip m:\bldforge_AOMS_DEV\WebSphere_AVOB\*
just add a slash before your * selector

Applying the patch command using files in different directories in Linux

I'm trying to apply a patch using 2 files in different directories. The output file should be in a different directory too. The first file is in /var/local/documents/document.xml and patch file is located in /var/local/patches/patch.diff and I want the output file should be created in /var/local/final/final.xml.
When the files are located in the same directory, this command works:
patch document.xml -i patch.diff -o final.xml
But when they are in separate directories and I try to use the following command:
patch
/var/local/documents/document.xml -i
/var/local/patches/patch.diff -o
/var/local/final/final.xml
I get the following error:
(Stripping trailing CRs from patch.)
patching file {file}
Hunk#1 FAILED at 20.
1 out of 1 hunk FAILED -- saving rejects to file {file}
I've read somewhere that I should use -d and -p to work correctly with directories but I have no clue how I should do it...
Yes, it's -p switch (in your case it should strip 2 entries from patch path):
cd /var/local/documents
patch -p 2 -o ../final/final.xml document.xml < ../patches/patch.diff
Try this:
$ mv /var/local/final/final.xml /var/local/final/document.xml
$ (cd /var/local/final && patch document.xml) < patch.diff
$ mv /var/local/final/document.xml /var/local/final/final.xml

Command to zip a directory using a specific directory as the root

I'm writing a PHP script that downloads a series of generated files (using wget) into a directory, and then zips then up, using the zip command.
The downloads work perfectly, and the zipping mostly works. I run the command:
zip -r /var/www/oraviewer/rgn_download/download/fcst_20100318_0319.zip /var/www/oraviewer/rgn_download/download/fcst_20100318_0319
which yields a zip file with all the downloaded files, but it contains the full /var/www/oraviewer/rgn_download/download/ directories, before reaching the fcst_20100318_0319/ directory.
I'm probably just missing a flag, or something small, from the zip command, but how do I get it to use fcst_20100318_0319/ as the root directory?
I don't think zip has a flag to do that. I think the only way is something like:
cd /var/www/oraviewer/rgn_download/download/ && \
zip -r fcst_20100318_0319.zip fcst_20100318_0319
(The backslash is just for clarity, you can remove it and put everything on one line.)
Since PHP is executing the command in a subshell, it won't change your current directory.
I have also get it worked by using this command
exec('cd '.$_SERVER['DOCUMENT_ROOT'].' && zip -r com.zip "./"');
cd /home/public_html/site/upload/ && zip -r sub_upload.zip sub_upload/
Use the -j or --junk-paths option in your zip command.
From the zip man page:
-j
--junk-paths
Store just the name of a saved file (junk the path), and do not store
directory names. By default, zip will store the full path (relative
to the current directory).

Resources