Change Default Text Encoding in Unrar Console
When extracting archives containing filenames from different language
sets, console-based unrar can produce garbled characters
(mojibake) if the encoding does not match your system environment. This
article provides straightforward methods to change and configure the
default text encoding in unrar, including using the
built-in charset switch, adjusting system environment variables, and
setting persistent configuration defaults.
Method 1: Use
the -sc Switch in the Command Line
The command-line version of RAR/UnRAR includes a built-in character
set switch (-sc) to specify the encoding for text
operations.
The syntax is:
unrar -sc<charset>[objects] <command> <archive>Charset Values:
f: UTF-8a: ANSI (Windows code page)o: OEM (DOS code page)u: Unicode (UTF-16)
Object Values:
c: Archive commentsl: List files
Example:
To force unrar to use UTF-8 for reading list files and
comments during extraction:
unrar -scfl x archive.rarMethod 2: Configure System Locale Variables (Linux & macOS)
On Unix-based operating systems, unrar relies heavily on
standard POSIX locale variables (LANG,
LC_CTYPE, or LC_ALL) to determine how text is
rendered to the terminal.
Check your current locale:
localeRun
unrarwith an overridden UTF-8 locale:LC_ALL=en_US.UTF-8 unrar x archive.rarMake the encoding permanent: Add the locale configuration to your shell profile (
~/.bashrc,~/.zshrc, or/etc/environment):export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8Apply the changes immediately:
source ~/.bashrc
Method 3: Change Active Code Page in Windows (CMD / PowerShell)
In Windows, the command prompt defaults to legacy OEM code pages (e.g., CP437). To display and process UTF-8 filenames correctly:
- Open the command prompt.
- Change the active console code page to UTF-8 using
chcp:chcp 65001 - Run your extraction command:
unrar x archive.rar
Method
4: Set Persistent Default Parameters via the RAR
Variable
To avoid typing encoding switches repeatedly, define the
RAR environment variable. The unrar binary
automatically reads this variable for default switches every time it
executes.
On Linux/macOS: Add this line to
~/.bashrcor~/.profile:export RAR="-scf"On Windows (Command Prompt):
setx RAR "-scf"
Alternatively, on Linux systems, you can create or edit
/etc/rarrc (system-wide) or ~/.rarrc
(user-specific) and add default switches:
-scf
Handling Legacy RAR4 Archives with Specific Encodings
Old archives created under RAR4 format do not store Unicode headers
and rely on the local OEM/ANSI code page of the operating system where
they were created. If unrar fails to translate these
filenames properly:
Use
unaras an alternative: Theunarutility supports an explicit encoding flag (-e):unar -e GBK archive.rar unar -e Shift-JIS archive.rar unar -e CP1251 archive.rarFix filenames post-extraction using
convmv(Linux):convmv -f cp936 -t utf-8 --notest -r ./extracted_folder