9

Download, extract and copy the file from a folder containing a version on its be...

 3 years ago
source link: https://www.codesd.com/item/download-extract-and-copy-the-file-from-a-folder-containing-a-version-on-its-behalf.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Download, extract and copy the file from a folder containing a version on its behalf

advertisements

I'm writing a bash script that downloads an compressed archive from an universal URL (in which new release of the software will automatically be presented), extracts it and copies a file called wimboot to a folder.

This is what I currently have:

sudo curl http://git.ipxe.org/releases/wimboot/wimboot-latest.tar.gz -o ./wimboot.tar.gz

sudo tar -zxvf ./wimboot.tar.gz #Extracts into a folder called "wimboot-2.5.2-signed", in it is the file I need ("wimboot").
cd ./wimboot*/
sudo cp wimboot /my-folder/

But this doesn't work. Is there a method that will allow me to do this?


You can ask tar for a file listing (-t option), which you can then grep for wimboot -- that should give you the relative path to the file also. A naive first try would be something like:

src_file=$(tar tf wimboot.tar.gz | grep wimboot)
cp "$src_file" my_folder/

But you will probably want to add some error checking and stuff to that. And probably a more complicated grep expression to ensure you get the one thing you're after.

There's also no need to extract the entire archive. You can just ask tar to extract the file you're interested in:

tar zxf wimboot.tar.gz "$src_file"


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK