Skip to content
Follow
Ubuntu Linux

Managing RAR Files on Ubuntu: Unrar & Rar Commands Guide

Richard
Written by
Richard
Updated 6 min read
How to Install Nextcloud AIO on Ubuntu Linux
How to Install Nextcloud AIO on Ubuntu Linux
⚡ Quick Answer

To open RAR files on Ubuntu, install the unrar tool with sudo apt install unrar, then run unrar x filename.rar to extract an archive or unrar l filename.rar to list its contents. To create RAR files, install the rar package with sudo apt-get install rar. If apt cannot find unrar, enable the multiverse repository and run sudo apt update first.

Advertisement

About unrar command:

Managing RAR files on Ubuntu takes two terminal tools: unrar opens compressed archives and rar creates them. Ubuntu doesn’t ship with either, so install them before you work with .rar files.

Advertisement
📝Good to KnowTo set up the extraction tool, open a terminal and run sudo apt install unrar.

If apt can’t find the package, the multiverse repository is probably disabled. unrar is not free software, so Ubuntu keeps it there. Enable multiverse, run sudo apt update, and try again.

The rar command creates RAR files on Ubuntu Linux. It is the companion to unrar, which only reads archives and cannot build them. The rar package is a trial version of the commercial RAR tool, so expect a licensing notice if you use it heavily.

Syntax:

The syntax is the format a command expects: the command name, then any options, then the archive name, then any files or folders. You can reorder some of the options, but the overall pattern must stay the same for both `unrar` and `rar`. If a command returns a usage message instead of doing the work, check the order first.

The unrar package isn’t installed on Ubuntu Linux by default, so you must install it before you can open any RAR file. Typing unrar without it gives you a “command not found” message.

Advertisement

Run the command below to install it. You need an account with sudo rights, and you will be asked for your password. The terminal won’t show the characters as you type, which is normal.

🐧Bash / Shell
sudo apt install unrar

Below is an example of the syntax for the unrar command. The first item is the action you want, such as extracting or listing. The last items are the archive name and, optionally, a destination folder.

💻Code
unrar [options]

Options:

Command line options are switches or flags that change how a command runs. You type them after the command name, separated by spaces. The same command can do very different things depending on which option you give it.

Below are some options for the unrar command:

 Options:Replace Options: with the options to run with the uptime command
 -eUse the -e option to extract files without archived paths
 -l, [t[a],b]  Use the -l option to list archive contents [technical[all], bare]
 -tUse the -t option to test archive files
-xUse the -x option to extract files with full path
-pUse the –p option to create an archive and set a password
 -V, –versionoutput version information and exit

With unrar installed, follow the steps below to extract and manage RAR files. Run each command from the folder that holds the archive, or give the full path to the file. You can check where you are with the pwd command.

Advertisement

Extract RAR files

You extract RAR files on Ubuntu with the unrar command in your terminal. You have two choices:

  • Unpack everything into your current folder with a single command.
  • Point the tool at a destination folder if you want the contents placed somewhere else.

Check the current folder first. Archives can hold a lot of loose files, and unpacking them into a crowded folder makes a mess that is tedious to clean up.

💻Code
unrar e filename.rar

To extract a RAR file into a specific directory, use the unrar command with the -x option and add the destination folder at the end of the command. Make sure the folder exists before you run it. If you are unsure, create it first. When the command finishes, the extracted files appear in that folder with their original subfolders.

💻Code
unrar x filename.rar /path/to/extracts

List RAR file content

To list the content of a RAR file without extracting it, run the unrar command with the -l option. The terminal prints the file names, sizes and dates stored in the archive. This is a quick way to see what you are about to unpack.

Advertisement
💻Code
unrar l filename.rar

Create RAR file on Ubuntu Linux.

You can use the command line utility “rar” to create a RAR file in Ubuntu Linux. First, make sure the “rar” package is installed by running the command below.

🐧Bash / Shell
sudo apt-get install rar

Create RAR archive

Once the rar package is installed, run the command below to create a RAR archive. Replace the archive name and the file names with your own. The new .rar file is created in the current folder unless you give a different path.

💻Code
rar a filename.rar file1 file2 file3 file4 file100

To add files to an existing RAR archive, use the rar command with the -u option. It updates the archive, adding files that are new and replacing ones that have changed. Your original files stay where they are, since the archive only holds copies.

💻Code
rar u filename.rar file7 file8 file9

Password protect RAR archive

⚠️WarningTo password protect a RAR archive on Ubuntu, add the -p option to the rar command when you create the archive.

The command then prompts you for a password, so the files are locked from the start. Pick a password you will remember. A RAR archive can’t be opened without it, and there is no recovery option.

Advertisement
💻Code
rar a -p filename.rar file1 file2 file3 file4 file100

When you run it, the command prompts you to create a password. The characters don't show as you type. You may be asked to type it a second time to confirm. To open the archive later, unrar asks for the same password.

Check the man pages for more about the unrar and rar commands. They list every option and are a good reference when you need something beyond the basics. Press q to leave a man page.

unrar man page:

💻Code
Usage:     unrar <command> -<switch 1> -<switch N> <archive> <files...>
               <@listfiles...> <path_to_extract/>

<Commands>
  e             Extract files without archived paths
  l[t[a],b]     List archive contents [technical[all], bare]
  p             Print file to stdout
  t             Test archive files
  v[t[a],b]     Verbosely list archive contents [technical[all],bare]
  x             Extract files with full path

<Switches>
  -             Stop switches scanning
  @[+]          Disable [enable] file lists
  ad[1,2]       Alternate destination path
  ag[format]    Generate archive name using the current date
  ai            Ignore file attributes
  ap<path>      Set path inside archive

rar man page

💻Code
NAME
       rar - archive files with compression

SYNOPSIS
       rar <command> [-<switch 1> -<switch N>] archive [files...] [@listfiles...] [path_to_extract]

COMMANDS
       After the program name comes a command and then optional switches with dashes before them.
       A summary of commands is included below.  For a complete description, run rar -?

       a      Add files to archive.

       c      Add archive comment. Comment length is limited to 256 KB.

       ch     Change archive parameters.  Can be used with most of archive modification options.

       cw     Write archive comment to a specified file.

       d      Delete files from archive.

       e      Extract files to current directory. Does not create any subdirectories.

That should do it!

Conclusion:

  • This article covered how to use the unrar and rar commands to manage RAR files in Ubuntu Linux.
  • The unrar command extracts, lists and tests RAR archives, while the rar command creates them.
  • If you follow the syntax and options shown above, you can extract, list and test RAR files with unrar and create RAR archives with rar.
  • For added security, use the -p option with the rar command to password-protect an archive.
  • With these commands you can handle RAR files in Ubuntu Linux entirely from the terminal.

Have a question about this guide?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *