Unzipping files in unattended mode

16

When I use the unzip command from Linux machine and the files under ZIP already exists on my local directory, I get the interactive question: (if I want to replace the files from the ZIP with the existing files on my Linux machine

How to use the unzip command without this interactive question?

 [@superuser]# ls -ltr

 total 0
 -rw-r--r--    1 root     root            0 Nov 15 15:13 all_my_files1
 -rw-r--r--    1 root     root            0 Nov 15 15:13 all_my_files2

[@superuser]# unzip MY_FILES.zip

    Archive:  MY_FILES.zip
    replace all_my_files1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
        inflating: all_my_files1.txt  
        inflating: all_my_files2.txt  

jennifer

Posted 2010-11-15T13:02:13.463

Reputation: 897

Answers

21

As the unzip(1l) man page states, pass -o to unzip in order to force overwriting of existing files without prompting.

Ignacio Vazquez-Abrams

Posted 2010-11-15T13:02:13.463

Reputation: 100 516

Caveat: a zip comment will prompt you to press Q or any other key to proceed and hang execution. The only way I came up with to avoid it is to pass -q but this will also cause unzip to not show the list of files being unzipped. – Artem Russakovskii – 2018-09-12T23:04:16.573

8

You want the -o option:

unzip -o MY_FILES.zip

Source

overwrites existing files without prompting. This is a dangerous option, so use it with care. (It is often used with -f, however.)

ChrisF

Posted 2010-11-15T13:02:13.463

Reputation: 39 650