How Unrar Handles Files Matching Archive Name
When using the unrar utility to extract an archive that
contains a file sharing the exact same name and extension as the archive
itself, a direct file collision occurs in the target directory. This
article covers how unrar detects this naming conflict, the
default interactive prompts it displays, the technical failures that
occur if an overwrite is forced, and the command-line flags required to
extract the file safely.
The Default Interactive Prompt
By default, unrar detects that the destination file
already exists—because the archive file itself is occupying that path in
the current working directory. Before writing any data to disk,
unrar halts the operation and displays an overwrite
confirmation prompt:
file.rar already exists. Overwrite it ?
[Y]es, [N]o, [A]ll, n[E]ver, [R]ename, [Q]uit
At this stage, you can choose how to proceed:
- [N]o / n[E]ver: Skips extracting the conflicting file, leaving the source archive untouched.
- [R]ename: Allows you to manually type a new filename for the extracted file.
- [Q]uit: Aborts the entire extraction process.
What Happens If You Force an Overwrite
Selecting [Y]es or executing the command with the
force-overwrite flag (-o+) attempts to write the extracted
content directly over the source archive file. The outcome depends on
your operating system:
- Windows: The operating system enforces mandatory
file locking. Because
unrarcurrently holds an open read handle on the archive file, Windows denies write access. The utility fails with a write error (such asCannot create file.rar: The process cannot access the file because it is being used by another process). - Linux and macOS: POSIX systems permit overwriting
or truncating open files. If
unrartruncates the file to begin writing extracted data, it destroys the unread portion of the archive it is actively parsing. This results in immediate extraction failure, generating errors such asUnexpected end of archiveorChecksum error.
Safe Extraction Methods
To prevent write failures or potential data loss, handle the collision using one of the following methods:
1. Automatic Renaming
Use the -or switch to instruct unrar to
automatically rename the extracted file if a duplicate name exists:
unrar x -or archive.rarIf archive.rar contains a file also named
archive.rar, the newly extracted file will be saved
automatically as archive(1).rar.
2. Extracting to a Different Directory
Specify a destination folder so the extracted file does not share the same directory space as the source archive:
unrar x archive.rar ./extracted_files/Because the destination path contains no existing file by that name, the extraction completes without prompts or conflicts.
3. Skip Conflicting Files
If you do not need the conflicting file, use the -o-
switch to suppress prompts and skip any file that matches an existing
filename:
unrar x -o- archive.rar