Find the answer to your Linux question:
Results 1 to 8 of 8
Hi, I wonder if someone know if its possible to make a script that unrar all files in folders under /blah/* ? So let say there is folders like: /blah/something/..files.. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2011
    Posts
    9

    Script to unrar lotsa dirs.


    Hi, I wonder if someone know if its possible to make a script that unrar all files in folders under /blah/* ?

    So let say there is folders like:
    /blah/something/..files..
    /blah/some_else/..files..

    How can I unrar files in those dirs in a script?
    Hope anyone understand what I mean with my bad english.

  2. #2
    Just Joined!
    Join Date
    Nov 2007
    Posts
    5
    Hello there !

    It's really easy:

    Lets say you are currently in /home/user directory

    So you just type the command:

    find ./ -name "*.gz" -exec gunzip {} \;

    With this command, we are instructing the find command to look for *.gz files in the current directory in a recursive way and then apply the gunzip command to the resulting files.

    Hope this helps !

    Santiago

  3. #3
    Just Joined!
    Join Date
    Dec 2005
    Posts
    9

    easy scripts....unrar lotsa dirs.

    One of my favorite ways to do stuff like this is to develop a script on the fly...

    Begin by getting a list of the files...from a parent directory, try something like...

    find . -name "*rar"

    then pipe that to awk to construct the command...

    find . -name "*rar"|awk '{print "unrar x " $1}'

    if this produces the desired list, pipe it through sh to execute...

    find . -name "*rar"|awk '{print "unrar x " $1}'|sh

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Nov 2007
    Posts
    5
    Quote Originally Posted by stuman View Post
    One of my favorite ways to do stuff like this is to develop a script on the fly...

    Begin by getting a list of the files...from a parent directory, try something like...

    find . -name "*rar"

    then pipe that to awk to construct the command...

    find . -name "*rar"|awk '{print "unrar x " $1}'

    if this produces the desired list, pipe it through sh to execute...

    find . -name "*rar"|awk '{print "unrar x " $1}'|sh

    Yet I think my solution is simpler and clever as it uses just 1 bash instruction, and it's also faster than yours....

  6. #5
    Just Joined!
    Join Date
    Jul 2008
    Posts
    93
    Quote Originally Posted by scampuzano View Post
    Yet I think my solution is simpler and clever as it uses just 1 bash instruction, and it's also faster than yours....
    It's really unfortunate that "gunzip" does not do the same thing as "unrar x". Otherwise you might have a point.

  7. #6
    Just Joined!
    Join Date
    May 2011
    Posts
    9
    Works like a charm, just one thing. If it found a rar in /path/to/a/*.rar, I want it to unrar it to /path/to/a/ too, not to /path/to/ as it is now. Any easy way to solve?

    I have to make some better example.

    I cd to /tmp, and there I fire the script above. And in /tmp there are serval dirs, and inside each of it there is a rar to unrar. But I want them to be decompressed to same dir as the .rar-file.
    ie: /tmp/a/a_rar_file.rar -> /tmp/a/decompressed_rar.extention
    /tmp/b/another_rar_file.rar -> /tmp/b/decompressed_another_rar_file.extention

    Hope you understand better now
    Last edited by yabbah; 12-06-2011 at 10:56 AM.

  8. #7
    Just Joined!
    Join Date
    Dec 2005
    Posts
    9
    I wasn't after "elegant" or even "simple". What I was after was a way to approach "scripting" using other tools that can be executed one step at a time, allowing the user to see what is being built as they go, then commit it when it is right. I often use this technique, and there is usually a "sed" command in there somewhere to modify what is found.

    For instance, in a system where there are lots of programs after a mass recompile it may be necessary to recompile all compiles that failed. Listing the "*.err" files, passing through "cut" to remove intermediary directories, then "sed" to strip off the ".err" part leaving just the program name then "awk" to build a new compile command works well. (this is applicable to a Lawson system on AIX or HPUX).

    Also, by seeing the list as it is being found the user may see a file they don't want to extract, which can easily be excluded by passing it through a "grep -v". When finding your way around a *nix system, it is reassuring to be able to preview the individual file commands...perhaps pass it into "more" for review, then pass it to "sh" instead of "more" to actually execute...

    The purpose is to become comfortable with piecing together a series of piped commands which increases familiarity with what is actually available at the command line. Speed is not really the issue for such "one time" tasks.

  9. #8
    Just Joined!
    Join Date
    May 2011
    Posts
    44
    Quote Originally Posted by clowenstein View Post
    It's really unfortunate that "gunzip" does not do the same thing as "unrar x". Otherwise you might have a point.
    Derp, how about:
    Code:
    find ./path/to/archives -name '*.rar' -exec unzip e {} \;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •