How to Exclude Files When Extracting with Unrar
Extracting RAR archives using the command-line utility
unrar often involves files you do not need, such as text
documents, system files, or large media assets. You can configure
unrar to selectively bypass these files during extraction
by using the -x exclusion switch. This guide explains how
to exclude specific file names, wildcards, directories, and file lists
to streamline your extraction process.
The Basic Exclusion Switch
(-x)
To exclude a file or a pattern during extraction, append the
-x switch to your unrar command followed
immediately (or with a space) by the file name or mask.
Basic syntax:
unrar x -x<pattern> archive.rarNote: Use the x command to preserve the archive's
internal directory structure, or e to extract everything
into a single flat directory.
Exclude a Specific File
To extract an archive while ignoring a specific file, provide the
full file name to the -x switch:
unrar x -xreadme.txt archive.rarExclude File Types Using Wildcards
You can use standard wildcards (* and ?) to
filter out entire formats or file types. To avoid shell expansion issues
in Linux or macOS terminal environments, always wrap wildcard arguments
in quotes.
To skip all .txt files:
unrar x -x"*.txt" archive.rarTo skip multiple distinct file types, append multiple -x
switches:
unrar x -x"*.nfo" -x"*.txt" -x"*.exe" archive.rarExclude Entire Folders
To prevent an entire directory and its contents from extracting, add wildcard slashes to indicate the path structure:
unrar x -x"*/sample/*" archive.rarOn Windows environments, use backslashes instead:
unrar x -x*\sample\* archive.rarExclude Files Using an External List File
When dealing with a long list of exclusions, you can write the
patterns into a plain text file (one pattern per line) and instruct
unrar to read it by combining -x with
@.
Create a file named
exclude.txt:*.nfo *.sfv *.txt */temp/*Run
unrarreferencing the exclusion list:unrar x -x@exclude.txt archive.rar