Print RAR File to Terminal Using Unrar
You can read the contents of a text file stored inside a RAR archive
directly in the terminal without extracting it to your disk first. The
standard unrar utility includes a built-in print command
that outputs file data straight to standard output
(stdout). This guide explains how to use the command,
suppress unwanted utility banners, and pipe the output to other
command-line tools.
The Basic Command
To print a file to the terminal, use the p (print)
command followed by the archive name and the specific file you want to
view:
unrar p archive.rar document.txtThis command decompresses document.txt in memory and
writes its text directly to the console.
Suppressing Archive Information and Headers
By default, unrar prints diagnostic information, version
headers, and archive comments along with the file contents. To output
only the clean text—which is essential for scripts or viewing long
documents—add the -inul (disable all messages) flag:
unrar p -inul archive.rar document.txtWith -inul enabled, standard output receives only the
raw content of the specified file.
Specifying Files in Subdirectories
If the target text file is located inside a folder within the RAR archive, provide the relative path to the file:
unrar p -inul archive.rar path/to/document.txtPiping Output to Other Commands
Because the p command sends text to standard output, you
can pipe the contents directly into other command-line utilities:
Page through long files:
unrar p -inul archive.rar document.txt | lessSearch for specific text:
unrar p -inul archive.rar document.txt | grep "search_term"Redirect the output to a new file:
unrar p -inul archive.rar document.txt > extracted_text.txt
Working with Password-Protected Archives
If the archive is encrypted, supply the password using the
-p switch directly after the command:
unrar p -inul -pYOUR_PASSWORD archive.rar document.txtIf you do not specify the password in the command, unrar
will prompt you to enter it in the terminal before printing the
contents.