Skip to content

Instantly share code, notes, and snippets.

@sphrak
Created Feb 3, 2019
Embed
What would you like to do?
Extract all rar archives recursively and delete if extraction was successful
#!/bin/bash
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]}
else
echo "Exit status failed: $?"
echo "Failed extracting: ${file}"
echo "${file}" >> failed.log
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment