Unrar Extract to Directory with Trailing Space
Extracting an archive with unrar to a directory ending
with a space depends directly on the host operating system, the
command-line shell interpretation, and built-in path sanitization rules.
While modern POSIX systems natively support trailing spaces in directory
names, Windows and certain versions of unrar enforce path
normalization that strips or rejects trailing whitespace to prevent
filesystem errors and security vulnerabilities.
Shell Escaping and Argument Parsing
When passing a destination path containing a trailing space via the command line, the terminal shell requires proper escaping or quoting. If quotes or escape characters are omitted, the shell treats the trailing space as an argument delimiter rather than part of the path name.
To direct unrar to extract into a directory named
my_folder , the path must be enclosed in quotation marks or
escaped with a backslash:
# On Linux/macOS
unrar x archive.rar "my_folder /"
unrar x archive.rar my_folder\ /
# On Windows Command Prompt / PowerShell
unrar x archive.rar "my_folder \"Behavior on Windows
Windows filesystems (NTFS and FAT) support trailing spaces internally, but the Win32 subsystem standardizes paths by automatically trimming trailing spaces and dots.
When running unrar.exe or WinRAR on
Windows:
- Argument Trimming: If you specify a target
directory like
"output ", the Win32 API strips the trailing space, resolving the path tooutput. - Path Sanitization: Due to historical path traversal
vulnerabilities and system instability caused by inaccessible folders,
unraractively sanitizes paths. It removes trailing whitespace from folder names defined both on the command line and within the internal RAR archive structure. - Extraction Result: Files are extracted into a standard folder without the trailing space.
Behavior on Linux and macOS (POSIX Systems)
POSIX-compliant filesystems treat spaces like any other valid byte in
a filename (except for null and /).
When running command-line unrar on Unix-like
environments:
- Literal Name Preservation: If the destination path
is quoted correctly,
unrarcreates the directory with the trailing space intact. - Archive Content Extraction: If the RAR archive
itself contains paths with trailing spaces, Unix versions of
unrarwill create those directories literally on disk, retaining the whitespace. - Navigating the Result: The resulting directory must
be accessed using quotes or escapes in subsequent commands (e.g.,
cd "my_folder ").