Recursive unRAR and delete

Just a continuation of a script mentioned at LinuxQuestions, to extract RAR archives in their respective directories in a directory tree. An additional option is available to delete the archive files after finishing extraction.

Update: This script is now contained in a GitHub repository instead of on this page.


12 thoughts on “Recursive unRAR and delete

    • Excellent stuff, and already in the Ubuntu archives. Thanks!

      Update: dtrx unfortunately doesn’t seem to do what this script does – Go into each subdirectory and extract RAR files in place. dtrx tries to extract files in the current directory, and the recursive mode is to “search inside the archives you specify to see if any of the contents are themselves archives, and extract those as well.”

    • Edit: It does now!

      I’m not sure how sequential RAR files work; whether they contain a reference to the next file to process, or whether it’s implicit in the file name (usually .rar, .r00, .r01 etc.). If you try this (remember to copy the directory first), it would be interesting to know the results.

  1. # ~/unrarr $ make test
    make: execvp: /home/casey/unrarr/ Permission denied
    make: *** [test] Error 127
    # ~/unrarr $ sudo make install
    install /usr/local/bin/unrarr
    sed -i -e ‘s#\(\./\)\?’ /usr/local/bin/unrarr
    install –mode 644 etc/bash_completion.d/unrarr /etc/bash_completion.d/
    install: target ‘/etc/bash_completion.d/’ is not a directory: No such file or directory
    make: *** [install] Error 1

    • The first error is very likely because you don’t have execute rights for the script. To fix it you can either check out the Git sources (where the execute flag is set already) or run chmod u+x A more unlikely cause would be either that the partition is mounted noexec or that SELinux rules are set up to prevent execution in the relevant context.

      The second error means you don’t have Bash completion installed. Nothing to worry about, but I should fix the Makefile so it doesn’t fail if it’s unavailable. You’ll have to re-run the installation with the latest sources; it should be fixed there. Thanks for the feedback!

      • Thanks for your prompt reply. In the meantime I’ve begun using another script called ‘unrarall’, which seems to suit my needs. So I’m good to go, but would happily continue testing your script if you would like to achieve wider compatibility.

        I do seem to have execute priveleges and I am using files cloned from your git repository:

        # ~/unrarr $ ls -l
        -rwxr-xr-x 1 casey users 6213 Feb 18 18:39
        # ~/download/scripts/bash/unrarr $ chmod u+x
        # ~/download/scripts/bash/unrarr $ ls -l
        -rwxr-xr-x 1 casey users 6213 Feb 18 18:39
        # ~/unrarr $ make test
        make: execvp: /home/casey/unrarr/ Permission denied
        make: *** [test] Error 127

        I ‘m not using the noexec mount option and am able to execute other shell scripts on this partition. It’s a LUKS encrypted partition, but I’ve never done anything with SELinux.

        I’m using Arch Linux and do have the bash-completion package installed. However, all this package’s files are located under /usr/share/bash-completion

        With the latest snapshot of your script, I still get the same error on “make test”, and get a slightly different one on “sudo make install”:
        # ~/unrarr $ sudo make install
        install /usr/local/bin/unrarr
        sed -i -e ‘s#\(\./\)\?’ /usr/local/bin/unrarr
        install –mode 644 shell-includes/ /usr/local/share/unrarr
        install: cannot stat ‘shell-includes/’: No such file or directory
        make: *** [install] Error 1

      • The sudo make install error is my fault; I forgot to include instructions on how to download the contents of the shell-includes directory. This is now in the readme file; it’s as simple as git submodule update --init.

        Regarding the permission problem, I really have no idea. I can’t reproduce it here, and others don’t seem to have the same problem. But if it’s 100% reproducible for you, would you be willing to report a bug with all relevant information?

    • Did you run bash -o noexec ./ to verify the syntax? Because the script sets the extglob (extended globbing, supported since Bash 2.02-alpha1) feature to enable some advanced syntax, which is not parsed when using noexec. If not, then which exact command did you run? Does make test work for you? If not, which version of Bash are you using?

  2. Is this script defunct? Or more likely, I am doing something wrong?

    I’m on Yosemite 10.10.5
    I’ve installed unrar (tested, working)
    I’ve installed shunit2 (via Homebrew in Terminal)
    But when run I get errors with anything I throw at it…

    Where I point it to a folder (w/ delete)

    Pyramid:unrarr-master cola$ ./ –delete /Users/cola/Downloads/101057
    readlink: illegal option — f
    usage: readlink [-n] [file …]
    shunit2:FATAL unable to read from –delete

    When I point it to a folder (w/o delete)
    Pyramid:unrarr-master cola$ ./ /Users/cola/Downloads/101057
    readlink: illegal option — f
    usage: readlink [-n] [file …]
    /usr/share/shunit2/shunit2: line 1037: .: /Users/cola/Downloads/101057: is a directory
    ASSERT:Unknown failure encountered running a test

    Ran 0 tests.

    FAILED (failures=1)

    I really want to take advantage of this script! Sorry if I’m making some typical newbie mistake, but I hope you can help me through this struggle

    • The script isn’t defunct (although I haven’t used it for probably years), but rather it appears readlink doesn’t have the same options on OS X as on Linux. Can you try simply removing the -f option to readlink in It should be redundant.

      If that works, you can either submit a pull request or respond here, and I’ll make sure it’s merged.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s