Unzipping and Unraring

I can unzip or unrar a file without a problem, but how can I do the same for multiple zipped or rared files, without losing some of the contents.

When I try to do so, by selecting several zipped or rared files then right click then click on either “Extract here” or “Extract to Subfolders” the process starts without a problem. However, after everything has been extracted, and I have a look at the contents of the folders which have been extracted, I see that they are either empty or only have a few files.

I will get zipped files, photos from my brother, with upto 200 - 300 pictures, the whole zipped or rared files ends up being about 150MB - 200MB. If I get 3 or 4 such files, as I did after he came back from his trip to Australia, and sent 10 such files with over 1500 photos, I had to unzip each file individually, since when I tried to do 2 or more at a time, I managed only to extract a few pictures per zipped file.

Anyone know a solution?

Thanks.

> Anyone know a solution?

patience? (do one, look at its photos (whatever) while the second is
unpacking, etc…)


DenverD (Linux Counter 282315) via NNTP, Thunderbird 2.0.0.14, KDE
3.5.7, SUSE Linux 10.3, 2.6.22.18-0.2-default #1 SMP i686 athlon

That’s what I have been doing so far. I’m patient enough now, I’ve had all that practice. I want to do more files and I want to do them now. rotfl!

silkmaze schreef:

> I can unzip or unrar a file without a problem, but how can I do the same
> for multiple zipped or rared files, without losing some of the contents.
>
>
> When I try to do so, by selecting several zipped or rared files then
> right click then click on either “Extract here” or “Extract to
> Subfolders” the process starts without a problem. However, after
> everything has been extracted, and I have a look at the contents of the
> folders which have been extracted, I see that they are either empty or
> only have a few files.

I have the same problem with rar files that contain a space in the archive name.
To unpack it I resort to the command line:
rar x “bla bla001.rar” ~/home/chris/someplace

Chris Maaskant

silkmaze wrote:
> I can unzip or unrar a file without a problem, but how can I do the same
> for multiple zipped or rared files, without losing some of the contents.
> When I try to do so, by selecting several zipped or rared files then
> right click then click on either “Extract here” or “Extract to
> Subfolders” the process starts without a problem. However, after
> everything has been extracted, and I have a look at the contents of the
> folders which have been extracted, I see that they are either empty or
> only have a few files.

Maybe some day you develop enough courage to run an xterm with a shell
in it, like bash, zsh or ksh.
Then you discover that with a single line in this shell you can do tasks
many times faster and easier than in a GUI file manager.

> I will get zipped files, photos from my brother, with upto 200 - 300
> pictures, the whole zipped or rared files ends up being about 150MB -
> 200MB. If I get 3 or 4 such files, as I did after he came back from his
> trip to Australia, and sent 10 such files with over 1500 photos, I had
> to unzip each file individually, since when I tried to do 2 or more at a
> time, I managed only to extract a few pictures per zipped file.
>
> Anyone know a solution?

e.g. with
for file in *.zip;do unzip “$file”;done
Or, even shorter,
unzip *.zip
As unzip knows how to process the files in order when supplied with a
wildcard.

I did the same thing with windows, but I didn’t realise that I could run unzip in the command line. Can I run it in any directory or do I have to be in a specific directory, where unzip is stored, in order to run it?

Can I do the same with rar, is there a unrar for the cli or do I use unzip to extract from rar files as well?

You can run unzip from anywhere, but usually you want to be in the directory where the zip file is because the files will be unpacked underneath or in the same directory. Similarly for unrar.

One small correction to the last post. You want to quote the wildcard:

unzip '*.zip'

Otherwise unzip will treat the second and subsequent files as filenames to be extracted and of course that will not work.

> You can run unzip from anywhere, but usually you want to be in the
> directory where the zip file is

if unpacking multiple compressed files you have to be prepared when
(for example) two or more archives include a file named README or
ATT0001.JPG, then you are gonna have to make a decision to overwrite
or skip…

btw, if you were ‘comfortable’ at a M$ command line you should LOVE
it here…much more power here (yep, will take a while to learn the
new lingo, but POWER!!)…

again i throw out that word: just takes a little patience to learn
the new chants…or, you can avoid the pain by stuffing what you are
used to into /etc/bash.bashrc.local, like:

alias cd…=‘cd …’
alias copy=‘cp -i’
alias rename=‘mv -i’
alias md=‘mkdir’
alias rd=‘rmdir -i’

[note: some (all?) of those on the left of the equal sign might not
be from M$, since i left them in '95…maybe those are from
Warp…don’t recall now…]


see caveat: http://tinyurl.com/6aagco
DenverD (Linux Counter 282315) via NNTP, Thunderbird 2.0.0.14, KDE
3.5.7, SUSE Linux 10.3, 2.6.22.18-0.2-default #1 SMP i686 athlon

Good thinking. Another way would be to unzip each file in its own directory so that there would be no clashes on unzipping and then you would have to reconcile any clashes later. Say you have a bunch of zip files in the current directory. First make a directory named after the zip file without the .zip, then unzip in that directory using the -d option to unzip.

for i in *.zip
do
  mkdir "${i/.zip}"
  unzip -d "${i/.zip}" "$i"
done

The idiom ${i/.zip} means $i with .zip replaced with nothing, i.e. removed from string.

It pays to read man pages, because you will then sometimes go ah, now I understand why that option was invented.

but, i thought the purpose of his first post was to do them all at
the same time (which is why i said ‘patience’)…

hmmmmmm…i guess if i knew how to write a script i could make one
which would ‘look at’ all the archive file names in a directory and

  1. make a sub directory for each, with the same name as the archive
    (as long as no directory with that name already exists) and 2) unpack
    each…

all with ONE command…or even with one CLICK…if that click
directed the script to look in an always used (for example)
/home/[user]/archives_to_be_unpacked

THEN silkmaze could get back to being impatient… :wink:


see caveat: http://tinyurl.com/6aagco
DenverD (Linux Counter 282315) via NNTP, Thunderbird 2.0.0.14, KDE
3.5.7, SUSE Linux 10.3, 2.6.22.18-0.2-default #1 SMP i686 athlon

Just add a & to the end of the unzip command. The terminal output might be a bit messy, but that’s what you get for impatience. :stuck_out_tongue:

I actually interpreted “at the same time” as with one command. If you type that loop into bash, you can sit back and watch the mayhem.

Code:

for i in *.zip
do
mkdir “${i/.zip}”
unzip -d “${i/.zip}” “$i”
done

What would the code be when dealing with rar files (with unrar)?

Dunno, I am a bit busy right now and haven’t got time to look at the unrar help screen. But maybe you can.

OK, I have very limited skills at the terminal. I’m trying to figure out how to make how to make ken_yap’s code work for rar.
I tried this, but it doesn’t work?

for i in *.rar
do
mkdir “${i/.rar}”
unrar e “${i/.rar}” “$i”
done

I basically just plugged rar where Ken_yap
had zip. I know that zip and rar has different switches, but again I’m not experienced at the terminal. Any help?

I think Ark will work if you are running KDE, make sure you have rar/unrar installed as well.

With rar/unrar installed, I have /usr/share/doc/packages/rar/rar.txt = user’s manual for CLI.

Winrar will run using Wine.

@ken_yap and snakedriver, thanks for your quick replies. But we need to go back to beginning of thread
to understand my question.
post#1 silkmaze

I can unzip or unrar a file without a problem, but how can I do the same for multiple zipped or rared files

I understand about rar and zip and I use them from both gui (ark & xarchiver) and the cli. No problem there. But like silkmaze stated, it can be very tedious when processing multiple files. I have a lot of files archived and sometimes I end up processing 20-50 rar files at a time. I was looking for
a way to streamline the process. Sorry, I should have made myself clear at the beginning…:slight_smile:

So type in a loop like I showed you and do them all one after the other automatically. If your rar files have a path and they are distinct, extract with the path and there should be no clashes. Otherwise you could do something like this to extract to distinct directories.

for i in *.rar
do
  d="${i/.rar}"
  mkdir "$d"
  (cd "$d"; unrar e ../"$i")
done

unrar seems to have an “ad” switch which might do what you want without having to do the cd, but I’m not sure what the author means by append directory, did they mean prepend directory really.

@ken_yap thank you

for i in *.rar
do
d=“${i/.rar}”
mkdir “$d”
(cd “$d”; unrar e …/“$i”)
done

This command works perfectly for what I need. Thanks for your quick reply…:slight_smile: