If you are an experienced Linux user, you would have definitely dealt with various archive formats. For example, tar, zip, rpm, deb, 7z, and more. Extracting these archives requires either different commands, or different command line arguments in case the command is same. Well, if you always wanted a single command that could extract most of the commonly used archive formats without any complexity, your search ends here. In this article, we will discuss dtrx command, which can extract all the popular archive formats.
dtrx Command In Linux
The command name dtrx stands for ‘Do The Right Extraction’. Here is a snapshot of its description from the man page :
- OS – Ubuntu 13.04
- Shell – Bash 4.2.45
- Application – dtrx 6.5
A Brief Tutorial
Its very easy to extract archives using the dtrx command. Just pass the name of the archive (along with the extension) as command line argument to the dtrx command and press enter. That’s it.
Lets understand its usage through some practical examples.
1. Extract different archive formats easily
Lets take 3 different types of archives and see how easily the dtrx command can be used to extract them:
$ dtrx snownews-1.5.12.tar.gz $ ls snownews-1.5.12 snownews-1.5.12/ snownews-1.5.12.tar.gz
$ dtrx zattoo-4.0.5-i386.deb dtrx: WARNING: extracting /home/himanshu/Downloads/zattoo-4.0.5-i386.deb to zattoo-4.0.5-i386.deb.1 $ ls zattoo-4.0.5-i386.deb zattoo-4.0.5-i386.deb zattoo-4.0.5-i386.deb.1/
$ dtrx tbclock-master.zip $ ls tbclock-master tbclock-master/ tbclock-master.zip
So you can see that all three popular archive formats were easily extracted through dtrx command.
2. Recursively decompress archive files through -r option
If an archive file contains other compressed files, the dtrx command, in default mode, asks the user whether to uncompress them or not.
Here is an example :
$ dtrx compressed-archive-files.zip compressed-archive-files.zip contains 2 other archive file(s), out of 2 file(s) total. You can: * _A_lways extract included archives during this session * extract included archives this _O_nce * choose _N_ot to extract included archives this once * ne_V_er extract included archives during this session * _L_ist included archives What do you want to do? (a/o/N/v/l)
So you can see that the dtrx command leaves it up to the user. But, in case it is desired to uncompress all the archives contained within an archive without any manual intervention, just use the -r option.
$ dtrx -r compressed-archive-files.zip $
So you can see that when -r option was used, the dtrx command did not ask user for any confirmation and decompressed all the member archives.
$ ls compressed-archive-files/ attachments/ logtailer-0.5/ attachments.zip logtailer-0.5.tar.gz
3. Extract all the files into current directory using -f option
If it is not required to extract the files into a separate directory but rather required to extract them in the current directory, use the -f option.
Here is an example :
$ ls attachments.zip logtailer-0.5.tar.gz $ dtrx -f attachments.zip $ ls acid2-acid3-confusion konqueror-screenshots attachments.zip logtailer-0.5.tar.gz
So you can see that all the files of attached.zip were extracted in the current directory itself.
4. Do not extract the archives, just list their contents on stdout using -l option
If you want to know just the contents of the archived file rather than extracting it, this can be done by using -l option.
Here is an example :
$ dtrx -l logtailer-0.5.tar.gz logtailer-0.5/ logtailer-0.5/Makefile.in logtailer-0.5/README logtailer-0.5/AUTHORS logtailer-0.5/COPYING logtailer-0.5/ChangeLog logtailer-0.5/INSTALL logtailer-0.5/Makefile.am logtailer-0.5/NEWS logtailer-0.5/aclocal.m4 logtailer-0.5/configure logtailer-0.5/configure.in logtailer-0.5/install-sh logtailer-0.5/missing logtailer-0.5/mkinstalldirs logtailer-0.5/logtailer.cr
So you see that the contents of the archive were displayed on stdout but the archive itself was not decompressed.
5. Use -m option to extract meta-data from .deb or .gem files, instead of their normal contents
Here is an example of this:
$ dtrx -m ubuntu-tweak_0.8.5-1_all.deb
$ ls ubuntu-tweak_0.8.5-1/
conffiles control md5sums postinst prerm
So you can see that the meta-data was extracted from .deb file.
For more options, visit dtrx’s man page.
Here are some of the important links related to the dtrx command :
- Home Page
- Download Link
Users can also use command line download managers like apt-get and yum to download and install the utility from command line.
- All in one solution to extract any compressed file
- Very easy to use
- Does not come pre-installed in most of the Linux distributions.
I think that dtrx is a must have utility for any Linux user. It is one of the best command line tool available for decompressing files. Its USP is the ease in which it can be used to decompress any compressed file. Just install and try it out and do not forget to drop a note of thanks to me.
Have you ever used dtrx or any similar utility? Please share your experience with us.
The post dtrx – A Versatile Tool To Easily Extract tar, zip, cpio, rpm, deb, gem, 7z, cab, rar, and InstallShield Archives appeared first on MyLinuxBook.