1

To extract all 7z archives into their own folder, using the archive name as the folder name, I run the command:

7z x "*.7z" -o* 

E.g., if one has the two files a.7z and b.7z, then folders a and b will be created and they'll contain the content of a.7z and b.7z (keeping the directory structure), respectively.

Sometimes, I have many 7z archives, and I'd like to extract them using multiple cores. I read this answer by Artem S. Tashkinov:

7z decompression is single threaded and that's the limitation of the compression format

Therefore, I am looking at using parallel, since in my case I have multiple 7z archives.

I tried:

parallel -j4 '7z x {} -o{}' ::: *.7z 

However, if we go back to the example with the two files a.7z and b.7z, the command will try to extract the two files a.7z and b.7z to the folders a.7z and b.7z instead of a and b, which will crash the execution since a.7z and b.7z are already taken and are files. How can I fix that? I want to have two folders, a and b.

If that matters, I use Ubuntu.

2 Answers 2

3

parallel drops the extension if you specify {.} instead of {}:

parallel -j4 '7z x {} -o{.}' ::: *.7z 
1

Just a side note, about the * in -o{dir_path} option. The documentation states that

{dir_path}
This is the destination directory path [...] If you specify * in {dir_path}, 7-Zip substitutes that * character to archive name.

The proper syntax for your initial command is

7z x \*.7z -o\* 

that is, the second * has to be escaped as well otherwise the shell will try to expand it. You're probably using bash without the nullglob option that's why it works (it can't find a match so it passes it literally to 7z)...


Now, to run that command via gnu parallel you could either use * (escaped, as I said above):

parallel -j4 '7z x {} -o\*' ::: *.7z 

or drop the * and use parallel replacement string {.} as in Stephen's answer.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.