System info:

aggitan@moneque:~$ uname -a
Linux moneque 2.6.32-25-generic #44-Ubuntu SMP Fri Sep 17 20:05:27 UTC 2010 x86_64 GNU/Linux

aggitan@moneque:~$ 7z

7-Zip 9.04 beta  Copyright (c) 1999-2009 Igor Pavlov  2009-05-30
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?


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


I'm not aware of any direct solution but with a little bash loop you can do it in a terminal (if, as your question seems to suggest, 7zip is able to do everything you want except for extracting into a folder based on the filename). Try (in the directory with the archives):

for FILE in *.*; do DIR=${FILE%.*}; mkdir $DIR && 7z x -o$DIR $FILE ; done

The ${FILE%.*} extracts the filename without the extension.

  • you need to cd $DIR or otherwise tell 7zip to extract there... – Tobias Kienzler Oct 18 '10 at 12:49
  • if there are both stuff.zip and stuff.rar this will mix up their contents – Tobias Kienzler Oct 18 '10 at 12:57
  • The -o${FILE%.**} is telling to use the dir, but I should have reused the $DIR variable instead. I'll edit my answer. – Marcel Stimberg Oct 18 '10 at 12:58
  • About stuff.zip and stuff.rar: That's true, but I think the OP wanted to recreate file-roller's "Extract Here" behaviour which does not create folders like stuff.zip.extracted but only uses the filename without the extension. – Marcel Stimberg Oct 18 '10 at 13:02
  • that's true, +1ing – Tobias Kienzler Oct 18 '10 at 13:03

A little shell scripting might come to the rescue.

#! /bin/bash

for archive in "$@"; do (
    archive_dir="$(cd $(dirname "$archive"); pwd -P)"
    archive_name="$(basename "$archive")"
    # make a directory by appending `.d` to the archive file name
    mkdir -p "$name"
    cd "$name"
    # extract contents with full path, 
    # replace 'x' with 'e' to extract into $name directory
    7z x "${archive_dir}/${archive_name}"
); done

Paste the above into a file extract.sh (in the directory where you want to extract files) and then make it executable:

chmod +x ./extract.sh

The script creates a directory for each archive given on the command line by appending .d to its file name (e.g., for an archive stuff.zip it will create directory stuff.zip.d), and then extracts files from the archive into it.

You can invoke it in a terminal like this (use wildcards to extract multiple archives in one go):

./extract.sh stuff.zip stuff2.rar

Disclaimer: untested, so try it out with one or two sample archives before making the big run.

  • if there are both stuff.zip and stuff.rar this will mix up their contents – Tobias Kienzler Oct 18 '10 at 12:55
  • +1. although as Marcel states, that is file-roller's behaviour. so it depends on aggitan's exact intentions – Tobias Kienzler Oct 18 '10 at 13:09
  • Thank you for the script I'll try and use this in the future. – aggitan Oct 18 '10 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.