Commands.page Logo

Ubuntu Unzip Flag to Keep Old Files During Extraction

This article provides a concise overview of how to preserve existing files when extracting archives in Ubuntu. It identifies the specific command-line flag needed to prevent overwriting data when duplicate filenames are encountered during the extraction process using the standard unzip utility.

To keep old files when extracting duplicates in Ubuntu, you must use the -n flag with the unzip command. This flag instructs the system to never overwrite existing files. If a file in the archive matches a file already on your disk, the extraction process will skip that specific file and leave the original version intact.

The basic syntax for this command is:

unzip -n archive.zip

When you run this command, unzip checks each file in the archive against your current directory. If a duplicate is found, the existing file is kept, and the file from the archive is ignored. This ensures that your older data remains safe without requiring manual confirmation for each duplicate.