Unrar to Folder Named After Archive Automatically
When extracting RAR archives from the command line, keeping the
working directory organized often requires extracting each archive into
its own dedicated folder. Instead of manually creating directories with
mkdir for every file, the unrar utility
provides a built-in switch that automatically creates a destination
folder matching the archive name. This guide covers the exact command
and switches needed to unpack single or multiple RAR files into
automatically generated folders.
The Command
To extract a RAR file into a directory named after the archive, run:
unrar x -ad archive.rarBreakdown of the Options
x: Tellsunrarto extract files with their original directory structure intact. Usingxis generally preferred overe(which extracts all files flatly into a single directory, discarding internal folder structures).-ad: The critical switch meaning "append archive name to destination path." This flag automatically generates a new subdirectory using the base name of the.rarfile and places all extracted contents inside it.archive.rar: The target archive you want to extract.
For example, running unrar x -ad backup_2024.rar creates
a folder named backup_2024 in your current directory and
extracts all contents directly into it.
Extracting to a Specific Destination
If you want to extract into an automatic subdirectory inside a different destination path, append the destination directory path at the end of the command:
unrar x -ad archive.rar /path/to/destination/With the -ad flag active, unrar will create
the directory at /path/to/destination/archive/.
Extracting Multiple RAR Archives at Once
To automatically extract multiple archives into their respective directories in a single operation, use a wildcard wrapped in quotes:
unrar x -ad '*.rar'Each archive matching the pattern will be unpacked into its own uniquely named folder, preventing files from different archives from mixing together.