Unzip All Files In A Directory
This works in bash, according to this link:
unzip \*.zip
How to unzip all files in directory using shell script?
Install unzip:
sudo apt install
unzip or yum install unzip
Use this in the same directory you want to unzip the files:
unzip ‘*.zip’
If you want to put the uncompressed files in other directory, then use this:
unzip ‘*.zip’ -d /usr/sampleZip/ExampleDir
To put it into a shell script:
vim shellscript.sh
Then the script could be something like:
#!/bin/bash
unzip ‘*.zip’
After saving the script, to execute it:
./shellscript.sh
Recursively unzip all subdirectories while retaining file structure
You could try this:
#!/bin/bash
while :; do
mapfile -td '' archives \
< <(find . -type f -name '*.zip' -o -name '*.7z' -print0)
[[ ${#archives[@]} -eq 0 ]] && break
for i in "${archives[@]}"; do
case $i in
*.zip) unzip -d "$(dirname "$i")" -- "$i";;
*.7z) 7z x "-o$(dirname "$i")" -- "$i";;
esac
done
rm -rf "${archives[@]}" || break
done
Every archive is listed by
find
. That list is extracted in the correct location and the archives removed. This repeats, until zero archives are found.You can add an equivalent
unrar
command (I'm not familiar with it).Add
-o -name '*.rar'
tofind
, and another case tocase
. If there's no option to specify a target directory withunrar
, you could usecd "$(dirname "$i")" && unrar "$i"
.There are some issues with this script. In particular, if extraction fails, the archive is still removed. Otherwise it would cause an infinite loop. You can use
unzip ... || exit 1
to exit if extraction fails, and deal with that manually.It's possible to both avoid removal and also an infinite loop, by counting files which aren't removed, but hopefully not necessary.
I couldn't test this properly. YMMV.
How to extract all zip files in subfolders in same folder using powershell
I found the solution in case someone else has same issue
Get-ChildItem '.' -R -Filter *.zip | ForEach-Object {
Expand-Archive $_.FullName "$($_.DirectoryName)/$($_.Basename)" -Force
Remove-Item $_.FullName
}
From batch file, I Need to recurse directories (and sub directories) and unzip every zip file found into their current directory w/delete of archive
... do (
... 7z x ....
if errorlevel 1 (echo fail %%s) else (echo del %%s)
)
should fix your problem. 7zip
appears to follow the rules and return errorlevel
as 0 for success and non-zero otherwise. if errorlevel
operates on the run-time value of errorlevel
.
Related Topics
How to Send a Sequence of at Commands to a Serial Port in Bash
What Is the Recommended Way to Perform Source-Level Debugging of System Library Calls
Linux: Modpost Does Not Build Anything
Have One Folder with Files That Have the Same Name But Different File
Why Does Order in Which Input Libraries Are Specified Matter
(Master) at End of Terminal Prompt
How to Put the Current Running Linux Process in Background
Architecture of I386 Input File Is Incompatible with I386:X86-64
Specify the from User When Sending Email Using the Mail Command
How to Get Cmake to Use the Default Compiler on System Path
Install Marklogic Centos Virtualbox Vm
Best Posix Way to Determine If a Filesystem Is Mounted Read Only
Add Blank Line Between Lines from Different Groups
Netfilter-Like Kernel Module to Get Source and Destination Address
-Bash: /Usr/Bin/Yum: /Usr/Bin/Python: Bad Interpreter: No Such File or Directory
What Is Difference Between Arm64 and Armhf
What's the Difference Between Event-Driven and Asynchronous? Between Epoll and Aio