Sick Gaming
How to recursively search for RAR files and extract from directory (Ubuntu) - Printable Version

+- Sick Gaming (https://www.sickgaming.net)
+-- Forum: Computers (https://www.sickgaming.net/forum-86.html)
+--- Forum: Linux, FreeBSD, and Unix types (https://www.sickgaming.net/forum-88.html)
+--- Thread: How to recursively search for RAR files and extract from directory (Ubuntu) (/thread-85249.html)



How to recursively search for RAR files and extract from directory (Ubuntu) - xSicKx - 06-17-2018

First what I'd do is right click in the directory, open a terminal from it. Then just paste this command and you will see all rar files be expanded to the current directory.

Code:
find . -name '*.rar' -exec unrar e {} \; -exec rm {} \;

Code:
-exec rm {} \;

will only be run to remove the .rar file if the unrar-ing succeeds
(-exec unrar e {} \;)

i.e. unrar returns with exit status 0.

You can also do this using bash, using globstar option to recursively match glob pattern (*.rar), and rm each file if unrar-ing is successful:

Code:
shopt -s globstar
for f in **/*.rar; do
    unrar e "$f" && rm "$f"
done

Now I'm using Ubuntu 16.04 ltz as a home server. Use this command a lot with torrenting ;)