Ubuntu – Extract multiple 7z files with auto rename

7zipbash

I have a bunch of 7z files, some of which contain files that have the same name. Therefore, I would like to do auto rename.

I can do something like

find ./all -exec 7z x -pabc123 -oall/xml {} \;

to extract all the files, but this asks me for each archive whether or not I want to auto rename them. Is there a way I can just have it ask me once? Or better yet, pass that in as a command line option?

(Note that I have to use seven zip because it has a password.)

Best Answer

From the p7zip manual:

-ao (Overwrite mode) switch

Specifies the overwrite mode during extraction, to overwrite files already present on disk.

Syntax

-ao[a | s | t | u ]

Switch Description

-aoa Overwrite All existing files without prompt.
-aos Skip extracting of existing files.
-aou aUto rename extracting file (for example, name.txt will be renamed to name_1.txt).
-aot auto rename existing file (for example, name.txt will be renamed to name_1.txt).

Examples

7z x test.zip -aoa

extracts all files from test.zip archive and overwrites existing files without any prompt.

Commands that can be used with this switch

e (Extract), x (Extract with full paths)

See also

Switches: -y (assume Yes on all queries)

Looks like either the -aou or the -aot switch on the 7z command will do what you want, e. g.:

find all -exec 7z x -aou [OPTIONS...] {} \;
Related Question