How to Extract a Specific File Using Unrar
Extracting individual files from a RAR archive saves time and disk
space by avoiding the need to decompress the entire archive. This guide
covers the precise command-line syntax required to extract a specific
file using the unrar utility on Linux and Unix-like
systems, including options for preserving directory structures and
specifying destination directories.
Basic Command Syntax
The general syntax to extract a single file requires invoking
unrar, specifying an extraction command, passing the
archive name, and stating the targeted filename:
unrar e archive.rar path/to/file.extunrar provides two primary extraction commands:
e(Extract without paths): Extracts the specified file directly into the current working directory, ignoring any internal folder hierarchy inside the archive.x(Extract with full paths): Extracts the specified file while recreating its original directory structure as stored in the archive.
Step 1: List the Contents to Find the Exact File Name
Before extracting, verify the exact name and path of the target file
inside the archive using the list (l) or list bare
(lb) command:
unrar lb archive.rarThis lists all files in the archive with their internal directory paths, which you can use in the extraction command.
Step 2: Extract the File
Extracting to the Current Directory (Flattened)
To extract a file named document.pdf directly to your
current working directory without its parent folders:
unrar e archive.rar document.pdfIf the file is inside a subfolder in the archive (e.g.,
folder/document.pdf), provide the full internal path:
unrar e archive.rar folder/document.pdfExtracting with Directory Structure Preserved
To keep the internal folder structure when unpacking:
unrar x archive.rar folder/document.pdfThis creates the folder/ directory in your current
location and places document.pdf inside it.
Step 3: Specifying a Destination Directory
To extract the file to a different folder on your system, append the
destination path with a trailing slash (/) to the end of
the command:
unrar e archive.rar document.pdf /path/to/destination/Note: The trailing slash is required so unrar
recognizes the destination argument as a folder rather than a rename
target.
Handling Spaces in File Names
If the archive name or the file you want to extract contains spaces, wrap the paths in quotation marks:
unrar e "My Archive.rar" "Sub Folder/My Document.pdf" /destination/