351

I am writing a shell script that unzips a ZIP file into an existing hierarchy of files, potentially overwriting some of the files.

The problem is that the unzip command asks for confirmation:
replace jsp/extension/add-aspect.jsp? [y]es, [n]o, [A]ll, [N]one, [r]ename: y

Is there an option to force unzip to overwrite the files?

meetar
  • 175
Nicolas Raoul
  • 11,561

3 Answers3

513

According to http://www.manpagez.com/man/1/unzip/ you can use the -o option to overwrite files:

unzip -o /path/to/archive.zip

Note that -o, like most of unzip's options, has to go before the archive name.

foraidt
  • 6,628
71

If you need to unzip in order to replace the new files only, you can use

unzip -f archive.zip

But for future reference, you can just type

unzip 

and you will get a list of the arguments for this package.

The possible arguments, for this case, are:

-f  freshen existing files, create none
-n  never overwrite existing files         
-q  quiet mode (-qq => quieter)
-o  overwrite files WITHOUT prompting    

Use the one that you feel is more suited for your needs.

Greenonline
  • 2,390
2

Try using

unzip -o <filepath/zipfile.zip> -d <path where you want files>

-o is replace existing file, best is use unzip --help

Pavn
  • 129
  • 3