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?

3 Answers 3


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.

  • 1
    e.g: unzip -o ZIP_PATH, works as a modifier.
    – bonzofenix
    Jul 21, 2014 at 22:35
  • 25
    -o option should be used before any other arguments. Example: unzip -o /path/to/archive.zip -d /destination_dir
    – FelikZ
    May 28, 2015 at 8:48
  • 1
    @FelikZ Thanks for the detail, I added your (stripped down) example to the answer
    – foraidt
    May 28, 2015 at 11:57
  • 2
    @loretoparisi What are you talking about? This is a Linux question. Are you looking for something like Expand-Archive? Jan 9, 2018 at 14:46
  • its showing inflating: foldername/filename.php @foraidt Feb 26, 2019 at 11:03

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


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.

  • 9
    +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. May 9, 2017 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 🤷‍♂️ ? Apr 26, 2018 at 7:44
  • // , The difference is in the behavior if the file doesn't exist May 24, 2018 at 18:53
  • 1
    @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, 2019 at 21:10

Try using

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .