How to Extract Files with Wildcards in unrar

Extracting specific files from a large RAR archive without unpacking everything can save significant time and disk space. This guide explains how to use the command-line utility unrar to extract files matching specific wildcard patterns, detailing the correct commands, options for preserving directory structures, and the syntax required to prevent command-line parsing errors.

Basic Syntax

The unrar tool supports standard wildcards such as * (matches any sequence of characters) and ? (matches a single character).

The basic command structure is:

unrar <command> <archive.rar> "<pattern>"

Important: Always enclose the wildcard pattern in quotation marks ("*.txt" or '*.txt'). If quotes are omitted, your shell (such as Bash or Zsh) will attempt to expand the pattern against files in your current working directory before passing the arguments to unrar.


Choosing the Extraction Command: e vs x

When extracting files with unrar, select between two main commands:

  • e (Extract): Extracts files to the current directory (or a specified target), ignoring the internal folder paths stored in the archive.
  • x (Extract with full paths): Recreates the original folder hierarchy when extracting the matched files.

Common Examples

1. Extract by File Extension

To extract all PDF documents into the current folder without preserving the directory structure:

unrar e archive.rar "*.pdf"

To extract all PDF files while maintaining their original folder locations:

unrar x archive.rar "*.pdf"

2. Extract Files Matching a Specific Keyword

To extract all files that contain the word "report" anywhere in the filename:

unrar e archive.rar "*report*"

3. Extract Files Using Single-Character Wildcards

To match files where a specific character varies (such as file1.log, file2.log):

unrar e archive.rar "file?.log"

4. Extract into a Specific Directory

Append the target directory to the end of the command:

unrar x archive.rar "*.png" /path/to/destination/

5. Match Files within a Specific Subfolder

If the archive contains directories, target files inside a specific folder by including the path in the pattern:

unrar x archive.rar "images/*.jpg"