Take the 2-minute tour ×

System info:

aggitan@moneque:~$ uname -a

aggitan@moneque:~$ 7z

p7zip Version 9.04 (locale=en_US.utf8,Utf16=on,HugeFiles=on,2 CPUs)

I've got a folder that has 68 archives in it ranging from .rar, .ace, & .zip.

I want to extract all of these files using their folder name as the first directory ("Extract here")

If I use file-roller it halts at the first error, there doesn't appear to be an "ignore error" flag for file roller.

If I use 7zip it dumps everything into the current folder and doesn't use clean folders

How can I extract everything into separate folders without spilling everything into the current directory?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

for i in *; do mkdir "$i.extracted"; (cd "$i.extracted" && 7z x "../$i") || echo "Error with $i"; done

share|improve this answer
Make this for i in *; do mkdir "$i.extracted"; (cd "$i.extracted" && 7z x "../$i"); done. That way, if cd fails for a particular directory, 7z doesn't set to work in the current directory. –  Gilles Oct 18 '10 at 12:09
@Gilles: good point, thanks. Also added a error message (hope my brackets are correct) –  Tobias Kienzler Oct 18 '10 at 12:11
@Tobias: With the parentheses, you don't need cd ..: the parentheses create a subshell, and the directory change is local to that subshell. –  Gilles Oct 18 '10 at 12:16
@Gilles: once again I learned something new, thank you –  Tobias Kienzler Oct 18 '10 at 12:19
This did it for me, thank you. I cross posted to askubuntu should I link to this, copy paste your answer or can you post there? askubuntu.com/questions/8089/… –  aggitan Oct 18 '10 at 12:44

Your Answer


