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?


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.

| improve this answer | |
  • 1
    e.g: unzip -o ZIP_PATH, works as a modifier. – bonzofenix Jul 21 '14 at 22:35
  • 13
    -o option should be used before any other arguments. Example: unzip -o /path/to/archive.zip -d /destination_dir – FelikZ May 28 '15 at 8:48
  • 1
    @FelikZ Thanks for the detail, I added your (stripped down) example to the answer – foraidt May 28 '15 at 11:57
  • this does not work on Azure web sites (Windows). – loretoparisi Aug 25 '16 at 14:28
  • 1
    @loretoparisi What are you talking about? This is a Linux question. Are you looking for something like Expand-Archive? – Franklin Yu Jan 9 '18 at 14:46

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

unzip -f archieve.zip

But for future references, you can just type


and you will get a list of the arguments for this package. The possible arguments are 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 more suited for you needs.

| improve this answer | |
  • 7
    +1, I like the more subtle, friendlier version of "here's how to rtfm for context, but here's the relevant section of the m" approach. – Nathan Basanese May 9 '17 at 21:23
  • 1
    Also looked at the help, but didn't understand the diff. between -u update files, create if necessary and -f freshen existing files, create none 🤷‍♂️ ? – juanmirocks Apr 26 '18 at 7:44
  • // , The difference is in the behavior if the file doesn't exist – Nathan Basanese May 24 '18 at 18:53
  • @juanmirocks With -f, the newer files will not be extracted at all even if they are not on the destination (such as if a later version of the zip is created that has files that the previous unzip did not create). If you don't already know you want that, chances are you don't. On the contrary, -u will extract additional files not on the destination, ensuring nothing is missing from the destination which is in the zip. – Poikilos Feb 22 '19 at 21:10

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.