KOMPX.COM or COMPMISCELLANEA.COM   

Unzipping multiple files. Linux

Unzipping multiple zip files into a directory by Linux command line unzip. Contrary to possible expectations, unzip *.zip is not going to work, *.zip should be put into quotes:


unzip "*.zip"

There may be files with the same names in these archives. To avoid overwriting:


unzip -B "*.zip"

Unzip -B makes unzip to overwrite duplicates during extraction process, but saving a backup copy of each overwritten file. The names for these backup copy files are created by adding tilde ("~") at the end of the original names of the files. If a file extension is present, then "~" is added after it. If that is not enough, unique sequence number (up to 5 digits) is appended after the "~".

Unzip -B is not too practical though. For example, since when the sequence number range for numbered backup files gets exhausted (99999, or 65535 for 16-bit systems), the backup file with the maximum sequence number is deleted and replaced by the new backup version without notice ( more on the subject ). The number of files in an archive may not be always known in advance or may be more than possible sequence number range, so Unzip -B is not a great choice. Renaming duplicate files by adding "~" at the end of their names, after the extension, is not too convenient either.

But another built-in option is even worse. If the -B modifier is not used, each time a file with an existing name is being extracted, unzip asks replace example.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename:. And each time "r" must be hit, then a new name has to be input. So some bash or another script solving the problem should probably be prepared and used instead.

Operating systems
More