Skip to content

Instantly share code, notes, and snippets.

Created Feb 3, 2019
What would you like to do?
Extract all rar archives recursively and delete if extraction was successful
for file in $(find . -iname '*.rar'); do
echo "Extracting ${file}..."
dir=$(dirname ${file})
unrar e -y -o+ -p- "${file}" "${dir}"
# check exit status, if not 0 it failed
if [[ $? -eq 0 ]]; then
echo "Exit status: $?"
rm -vf ${dir}/{*.rar,*.r[0-9][0-9]}
echo "Exit status failed: $?"
echo "Failed extracting: ${file}"
echo "${file}" >> failed.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment