For quite a while I have found it a pain that unrar does not allow you to extract multiple files at once.
The other day I finally figured out how to get past this. Simply use xargs with place holders.

This command will unrar all the files in the current directory and any subdirectories to the directory /home/user/directory/

find . -iname "*.rar" | xargs -i unrar x {} /home/user/directory/
Share this post

6 Comments

  1. Anonymous

    find . -iname “*.rar” -exec unrar x {} /home/user/directory/ \;

    • Mark Davidson

      Guessing your suggesting a shorter alternative and you are completely right. I had actually just updated the original post with a shorter version. But yours is 100% valid and better than my original cheers.

      • Your original solution does not work with xargs (maybe you forgot -i). It does however work with GNU Parallel without the -i:

        find . -iname “*.rar” | parallel unrar x {} /home/user/directory/

        It also seems to be faster – probably because it uses more CPUs.

        The intro video for GNU Parallel shows other useful one liners: http://www.youtube.com/watch?v=OpaiGYxkSuQ

        • Mark Davidson

          Thanks for the correction Ole. I made an update to shorten the command and went a bit to far.
          Also thanks for suggestion of GNU Parallel, have just watched your first video and moving on to the second. Very cool stuff going to give it a go later and do a rewrite of this post.

  2. Gerhard

    xargs also supports a -p options btw, you can run tasks in parallel without using… parallel.

  3. The following command will do it recursively:
    [code]
    find . -iname “*.rar” | xargs -i unrar x -o- {} /target/directory/
    [/code]

Leave a Reply

CAPTCHA (required) Time limit is exhausted. Please reload CAPTCHA.