With this command, we can recursively unzip archives in a directory and its sub-directories and remain its structure in the current working directory.
find ../backUp/ -name "*.zip" |
xargs -P 5 -I fileName sh -c '
unzip -o -d "$(dirname "fileName")/$(basename -s .zip "fileName")" "fileName"
'
But when I run it, all the unzipped folders keep in the original directory. Can we hard-code basename and dirname in the bash environment?
adding example:
/backUp/pic1/1.zip
/backUp/pic2/2.zip
/backUp/pic3/3.zip
Goal:
/new/pic1/1-1.png
/new/pic1/1-2.png
/new/pic2/2-1.png
/new/pic2/2-2.png
/new/pic3/3-1.png
fileNamein shell code afterxargs -I fileNameis like embedding{}afterxargs -I {}. Don't. – Kamil Maciorowski Feb 21 '22 at 05:04"$(dirname "fileName")"to"hard-coded-name"? – ctrl-alt-delor Feb 21 '22 at 09:25foo/bar.zipwith a filedir/hello.txt, this should extract the file tofoo/bar/dir/hello.txt? – ilkkachu Feb 21 '22 at 09:42.zipfiles in what directories do you have what files are in the.zipfiles, what result do you get and what do you want to get instead? Or what else is your question aboutbasenameanddirname? It would be possible to replace thedirname/basenamecombination with other commands. – Bodo Feb 21 '22 at 09:54