Sick Gaming

Full Version: How to recursively search for RAR files and extract from directory (Ubuntu)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 {} \Wink

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 Wink