Today's article has you learning to extract an .rar file in Linux...

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
11,497
Reaction score
9,993
Credits
95,326
I'm always a bit amused with WinRAR having a Linux version. While we don't see many .rar files in the Linux realm, you never know what kind of files you'll want to extract. As such, knowing how to extract an .rar file's contents is probably worth learning. It's not too hard, just two commands you're really likely to need. The rest is covered in the man page, if you need to add a password or whatnot.


Feedback is awesome. (Also, this one was definitely authored by me.)
 


There is also a package available called rar, that allows you to create .rar archives.
So you can use rar for creating/compressing the archives and unrar to extract/decompress them.


Personally for extracting archives - I use a Python program called dtrx (Do The Right eXtract), which can decompress/extract any type of compressed format. As long as you have the appropriate decompression tools installed (e.g. unrar for rars, gunzip for zips, tar for .tar files etc).
It can deal with lots of other types of files: .cab, .7z, .xz, .tar.bz2, .tar.xz, .lzh, .gem etc etc.

dtrx is really handy if you deal with lots of different archive formats, and saves you from having to remember exactly what command-line switches you need in order to get a particular type of archive extracted.
So instead of having to remember a bunch of esoteric command line switches for each decompression tool, you can just use:
Bash:
dtrx /path/to/file.type
Where /path/to/ is the path to the file and file.type is the filename and extension (e.g. file.zip, or file.rar.
And dtrx will determine which tool to use and will pass the appropriate parameters.

So for a single .tar.gz file:
Bash:
dtrx ./somefile.tar.gz
And dtrx will automagically invoke tar (which in turn will invoke gunzip) to decompress and unarchive/extract the archive.

And if you have multiple archives in different formats in the current directory - and you want to extract them all, you could even do something like this:
Bash:
dtrx ./*.{rar,tar.gz,7z,zip}
And dtrx will attempt to extract ALL .rar, .tar.gz, .7z and .zip files that are in the current directory, using the appropriate tool for each file.

So dtrx saves you from having to worry about remembering a bunch of different command-line options for lots of different decompression/de-archiving tools. But in order for it to work, you must already have the appropriate tools installed for the types of files you want to extract.

Edit:
I forgot to mention this:
dtrx is in the package repositories of most
Linux distros. If it is not available in your distribution’s repositories, it can be installed as a local site package using pip for Python.
E.g.
Bash:
pip install dtrx
 
Last edited:
I use a Python program called dtrx (Do The Right eXtract),

Nice! Now that looks fascinating. I'd never heard of it until now.

That's one of the reasons I like this article writing thing. If you do it, you will learn so much.

It's like, if you don't know how to do something, just go online and tell people that you're going to do that something and how you're going to do it. Someone will chime in to call you an idiot and tell you the right way to do it!
 
Just a minor note: (AFAIK, I may be wrong) Tarballs (.tar) aren't ever compressed as-is. You need xz or gzip or whetever them to compress them; those are your .tar.xz, .tar.gz, etc. files.

Oh the nostalgia of the .rar file followed by the memory of never paying for winrar... <insert lots of comics and memes>
 
Heh... I had to double-check and, sure enough, I'd missed a '.gz' in the article. Good eyes.

And I had a WinRAR *and* a WinZIP license. The WinZIP came first and it just kept working even after I'd swapped to using WinRAR for my file compression needs. I'd be surprised if the same code didn't work today with the current version of WinZIP.
 

Members online


Top