I have multiple zipfile's (*.zip) in 3 different subdirectories.
Using the terminal, how would I unzip these into a different directory?
Not into the current directory.
I have multiple zipfile's (*.zip) in 3 different subdirectories.
Using the terminal, how would I unzip these into a different directory?
Not into the current directory.
Last edited by wyattwhiteeagle; 2 Weeks Ago at 03:09 PM.
Software Equivalents
https://help.ubuntu.com/community/SoftwareEquivalents
Bash Scripting
https://help.ubuntu.com/community/Be.../BashScripting
orCode:cd the/target/directory unzip path/to/the/zipfile'unzip' will unpack the given file into the current working directory or the directory given after the '-d' option, including any directory hierarchy inside the archive. If you want all the files without the hierarchy you can give unzip the option '-j' to unpack the files without reproducing the directory hierarchy. Since 'unzip' will only process one archive per call, you'll have to call it multiple times, once per archive. A loop might be useful ('for i in path1/zipfile1 path2/zipfile2 path3/zipfile3 ; do unzip "$i"; done').Code:unzip path/to/the/zipfile -d the/target/directory
Holger
Software Equivalents
https://help.ubuntu.com/community/SoftwareEquivalents
Bash Scripting
https://help.ubuntu.com/community/Be.../BashScripting
Last edited by wyattwhiteeagle; 2 Weeks Ago at 04:23 PM.
Software Equivalents
https://help.ubuntu.com/community/SoftwareEquivalents
Bash Scripting
https://help.ubuntu.com/community/Be.../BashScripting
Yes, you're missing the 'for i in ' part, which tells the shell that this is a loop and the variable i should be set to one of the listed values at the beginning of each iteration. You also might want to 'cd' into the target directory before running the loop or add a '-d' option with the target directory to the unzip command. And on the command line you don't need the single quotes I enclosed it in. Obviously, with a loop all archives will be unpacked into the same directory unless you do something really fancy - let's say two arrays, one holding the filenames, one holding the paths to extract to, looping over the indices to extract each file to the directory with the same index in the second array. With anything under ten files I probably wouldn't bother with a loop at all and just do the unzipping one at a time.
The usual warning: filenames with spaces in them can lead to really surprising results when doing shell-scripting ...Code:cd the/target/directory for i in /home/wyatt/Downloads/File-1.zip /home/wyatt/Desktop/Zipped/File-2.zip ; do unzip "$i"; done
Oops...missed your reply...let me read and try.
Please don't reply until after my next post.
What I tried didn't work.
What all am I missing in the script?
The script has...
Here's the output...Code:SRC="/home/wyatt/Desktop/Test-Folder-2/Image/Wyatts-Scripts.zip /home/wyatt/Desktop/Everything/Compressed/ZIP/Cheys-Place-GA.zip" TGT="/home/wyatt/Downloads" unzip "$SRC" -d "$TGT"
Code:wyatt@wyatt-hplaptop15ef1xxx:~$ /home/wyatt/Desktop/Test-Script.sh unzip: cannot find or open /home/wyatt/Desktop/Test-Folder-2/Image/Wyatts-Scripts.zip /home/wyatt/Desktop/Everything/Compressed/ZIP/Cheys-Place-GA.zip, /home/wyatt/Desktop/Test-Folder-2/Image/Wyatts-Scripts.zip /home/wyatt/Desktop/Everything/Compressed/ZIP/Cheys-Place-GA.zip.zip or /home/wyatt/Desktop/Test-Folder-2/Image/Wyatts-Scripts.zip /home/wyatt/Desktop/Everything/Compressed/ZIP/Cheys-Place-GA.zip.ZIP. wyatt@wyatt-hplaptop15ef1xxx:~$
Last edited by wyattwhiteeagle; 2 Weeks Ago at 05:03 PM.
Software Equivalents
https://help.ubuntu.com/community/SoftwareEquivalents
Bash Scripting
https://help.ubuntu.com/community/Be.../BashScripting
Thank you so very much.
The below worked.
Marking this as solved.
Code:cd /home/wyatt/Downloads for i in /home/wyatt/Desktop/Test-Folder-2/Image/Wyatts-Scripts.zip /home/wyatt/Desktop/Everything/Compressed/ZIP/Cheys-Place-GA.zip ; do unzip "$i"; done
Last edited by wyattwhiteeagle; 2 Weeks Ago at 05:38 PM.
Software Equivalents
https://help.ubuntu.com/community/SoftwareEquivalents
Bash Scripting
https://help.ubuntu.com/community/Be.../BashScripting
As I said, 'unzip' will unpack one file per call. By enclosing the list of files in quotes in post #6, you've turned it into one token. So now unzip looks for one file named '/home/wyatt/Desktop/Test-Folder-2/Image/Wyatts-Scripts.zip /home/wyatt/Desktop/Everything/Compressed/ZIP/Cheys-Place-GA.zip' and can't find it. But even if it would correctly split it into two tokens it wouldn't work; second and following parameters are interpreted as specific files to unpack from the archive given as the first parameter. That way you can selectively unpack only the files you need from an archive. To unpack multiple archives you really do need a loop as you've done in post #7.
If you need to unpack multiple files in different places, you'd do something like
This might actually be useful if you have a dozen or so archives to unpack into as many different directories ...Code:declare -a filenames=(the/first/file the/second/file the/'third and final'/file) declare -a targetdirs=(one/directory/ another/directory/ and/a/final/directory) for (( i=0 ; i<${#filenames[*]} ; i++)) ; do unzip ${filenames[i]} -d ${targetdirs[i]} done
Holger
Software Equivalents
https://help.ubuntu.com/community/SoftwareEquivalents
Bash Scripting
https://help.ubuntu.com/community/Be.../BashScripting
Not being an expert in bash scripts I take the easy route of Krusader double panel manager (similar to Double Commander). Although these tools do have a large footprint of dependencies.
Copy the zip(s) from ~/Downloads to target panel and just click to expand in its target.
There are additional features in Krusader Useractions.
Bookmarks