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..
...
- 12-05-2011 #1Just 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.
- 12-05-2011 #2Just Joined!
- Join Date
- Nov 2007
- Posts
- 3
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
- 12-05-2011 #3Just 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
- 12-05-2011 #4Just Joined!
- Join Date
- Nov 2007
- Posts
- 3
- 12-06-2011 #5Just Joined!
- Join Date
- Jul 2008
- Posts
- 81
- 12-06-2011 #6Just 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 09:56 AM.
- 12-06-2011 #7Just 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.
- 12-10-2011 #8Just Joined!
- Join Date
- May 2011
- Posts
- 44


Reply With Quote
