rar Command

The rar command is the command-line interface for the WinRAR archiver on Linux and Unix-like systems. It allows you to create, extract, list, and manage .rar archives. While .rar is a proprietary format, the rar and unrar tools are widely available for handling these files.

Syntax

rar <command> [ -switch1 -switch2 ... ] <archive> [ <files...> ] [ <@listfiles...> ] [ <path_to_extract...> ]
unrar <command> [ -switch1 -switch2 ... ] <archive> [ <files...> ] [ <path_to_extract...> ]

Description

The rar utility provides a comprehensive set of features for working with RAR archives, including solid archiving, encryption, and recovery records. The unrar utility is specifically for extracting files from RAR archives.

Common uses include:

  • Creating new .rar archives.
  • Extracting files from .rar archives.
  • Listing the contents of a .rar archive.
  • Creating password-protected archives.

Common Commands and Switches

Command/Switch Description
a Add files to archive.
x Extract files with full paths.
e Extract files to current directory (without paths).
l List contents of archive.
d Delete files from archive.
-p<password> Set password for archive.
-v Verbose mode (list files while processing).
-r Recurse subdirectories.

Examples

Create a RAR archive

rar a myarchive.rar file1.txt folder/

Creates myarchive.rar containing file1.txt and the folder/ directory.

Extract a RAR archive with full paths

unrar x myarchive.rar

Extracts all files from myarchive.rar, preserving their original directory structure.

Extract a RAR archive to current directory (without paths)

unrar e myarchive.rar

Extracts all files from myarchive.rar directly into the current working directory.

List contents of a RAR archive

unrar l myarchive.rar

Lists all files and folders within myarchive.rar without extracting them.

Create a password-protected RAR archive

rar a -pMySecretPassword secret.rar confidential.doc

Creates a password-protected archive named secret.rar.

See also