Graças aos conselhos de @Useless e @Orion, agora eu venci a função até a submissão. Agora, ele gera todas as extrações em segundo plano, não exclui mais os arquivos de origem e é 25% mais rápido para mim do que seu antecessor. @Gilles observou que a paralelização não é para todos, já que é um pouco caro para armazenamento. Porém, foi melhor para mim e, se você achar que pode usar esse script, eu o forneço abaixo:
extract () { # Extracts all archives and any nested archives of specified directory into a new child directory named after the archive.
IFS=$'\n'
trap "rm $skipfiles ; exit" SIGINT SIGTERM
shopt -s nocasematch # Allows case-insensitive regex matching
echo -e "\n=====Extracting files====="
skipfiles='mktemp' ; echo -e '\e' > $skipfiles # This creates a temp file to keep track of files that are already processed. Because of how it is read by grep, it needs an initial search string to omit from the found files. I opted for a literal escape character because who would name a file with that?
while [ "'find "$1/" -type f -regextype posix-egrep -iregex '^.*\.(tar\.gz|tar\.bz2|tar\.xz|tar|tbz|tgz|zip|rar|7z)$' | grep -ivf $skipfiles | wc -l'" -gt 0 ]; do #The while loop ensures that nested archives will be extracted. Its find operation needs to be separate from the find for the for loop below because it will change.
for z in 'find "$1/" -type f -regextype posix-egrep -iregex '^.*\.(tar\.gz|tar\.bz2|tar\.xz|tar|tbz|tgz|zip|rar|7z)$' | grep -ivf $skipfiles'; do
destdir='echo "$z" | sed -r 's/\.(tar\.gz|tar\.bz2|tar\.xz|tar|tbz|tgz|zip|rar|7z)$//'' # This removes the extension from the source filename so we can extract the files to a new directory named after the archive.
if [ ! -d "$destdir" ]; then
echo "Extracting 'basename $z' into 'basename $destdir' ..."
mkdir -p "$destdir"
if [[ "$z" =~ ^.*\.7z$ ]]; then 7z x "$z" -o"$destdir" > /dev/null &
elif [[ "$z" =~ ^.*\.rar$ ]]; then unrar x -y -o+ "$z" "$destdir" &
elif [[ "$z" =~ ^.*\.zip$ ]]; then unzip -uoLq "$z" -d "$destdir" 2>/dev/null &
elif [[ "$z" =~ ^.*\.(tar\.gz|tar\.bz2|tar\.xz|tar|tbz|tgz)$ ]] ; then tar -xaf "$z" -C "$destdir" &
fi
echo 'basename "$z"' >> $skipfiles # This adds the name of the extracted file to the omission list for the next pass.
else echo "Omitting 'basename $z', directory with that name already exists."; echo 'basename "$z"' >> $skipfiles # Same as last line
fi
done
wait # This will wait for all files in this pass to finish extracting before the next one.
done
rm "$skipfiles" # Removes temporary file
}