Force Unrar to Use a Specific Temp Directory
When extracting large RAR archives on systems with limited space on
the default root or drive partition, redirecting temporary files is
essential to avoid out-of-disk-space errors. This guide explains how to
force the unrar command-line utility to use a designated
temporary or working directory instead of the system default, ensuring
seamless extraction and better disk management.
Using the -w Switch
The most direct way to specify a temporary directory in
unrar is with the -w<path> switch. This
command tells the extraction tool to assign a custom work directory for
unpacking intermediate files.
The syntax requires appending your target directory directly to the flag:
unrar x -w/path/to/custom_temp archive.rarOn Windows, the command structure remains identical with Windows paths:
unrar x -wC:\CustomTemp archive.rarEnsure there is no space between the -w flag and the
path, and verify that the target directory already exists and has the
appropriate write permissions.
Using the
TMPDIR Environment Variable (Linux/macOS)
If you are using a build of unrar that relies on
standard system libraries to generate temporary files, setting the
temporary environment variable for the execution session will redirect
temporary data.
Run the extraction with TMPDIR prepended to the
command:
TMPDIR=/path/to/custom_temp unrar x archive.rarThis overrides the default /tmp location for the
duration of that specific command without altering system-wide
environment variables.
Using the
TEMP Environment Variable (Windows)
On Windows, command-line utilities frequently pull their temporary
workspace location from the TEMP or TMP
environment variables. You can redirect this in a Command Prompt
session:
set TEMP=D:\CustomTemp
set TMP=D:\CustomTemp
unrar x archive.rarThis ensures that any operations requiring temporary staging utilize
the designated drive rather than filling up your primary C:
drive.