Unrar Overwrite Only If Newer Switch
When extracting files using the command-line utility
unrar, you can prevent unnecessary file replacements by
restricting overwrites to files that are newer in the archive. This
article explains the exact command-line switches required—specifically
the -u (Update) and -f (Freshen) switches—and
demonstrates how to run them to update destination files safely.
The Primary Switch:
-u (Update)
The switch that tells unrar to overwrite files only if
the archived file is newer is -u.
When applied to an extraction command, -u performs an
"update" operation:
- It extracts files that do not exist yet in the destination directory.
- It overwrites existing files only if the file inside the RAR archive has a more recent modification timestamp than the local file.
- It leaves newer or identical existing local files untouched.
Usage Example
To extract an archive with full directory paths while updating only older files:
unrar x -u archive.rarTo extract directly into the current working directory without recreating internal archive paths:
unrar e -u archive.rarThe Alternative Switch:
-f (Freshen)
If your goal is to overwrite older files without extracting any new
files that do not already exist on disk, use the
-f (Freshen) switch.
- It checks files in the target directory that share names with files in the archive.
- It overwrites them only if the archived copy is newer.
- Unlike
-u, it skips any files in the archive that do not already exist in the target folder.
Usage Example
unrar x -f archive.rarSummary of Extraction Behavior
| Switch | Action on Missing Files | Action on Older Files | Action on Newer/Identical Files |
|---|---|---|---|
-u |
Extracts | Overwrites | Skips |
-f |
Skips | Overwrites | Skips |
-o+ |
Extracts | Overwrites | Overwrites |
-o- |
Extracts | Skips | Skips |