How to Force unrar to Overwrite Existing Files
When extracting RAR archives in automated scripts or standard
terminal sessions, the unrar utility prompts for user
confirmation whenever it encounters duplicate filenames. This guide
explains how to use the -o+ command-line switch to
automatically overwrite existing files without interactive prompts,
along with practical examples for everyday use.
The Overwrite Switch:
-o+
To force unrar to overwrite existing files
automatically, append the -o+ switch to your extraction
command. The switch is case-sensitive and must be written with the plus
sign (+) immediately following the lowercase letter
o.
Basic Usage Examples
Extracting with Full
Directory Paths (x)
In most cases, you want to preserve the internal folder structure of
the archive. Use the x command combined with
-o+:
unrar x -o+ archive.rarExtracting to a Specific Directory
To extract files to a designated folder while overwriting duplicates, specify the destination directory at the end of the command:
unrar x -o+ archive.rar /path/to/destination/Note: Ensure the destination path ends with a trailing slash
(/) so unrar recognizes it as a
directory.
Extracting Without
Directory Paths (e)
If you want to extract all files into a single flat directory,
ignoring any subdirectories inside the archive, use the e
command:
unrar e -o+ archive.rarKey Considerations
- No Space Between Characters: Do not place a space
between
-oand+. The argument must be supplied as-o+. - Skipping Files Instead: If you need the opposite
behavior—skipping existing files without prompting—use the
-o-switch instead. - Non-Interactive Environments: The
-o+switch is essential for cron jobs, Docker build processes, and bash automation where interactive terminal inputs (standard input) are disabled or unavailable.