What is Dtrx?
Dtrx stands for “
Do The Right Extraction“,
it’s an open source and very effective command-line application for *nix
systems that simplify your job of archive extraction easier.
The
dtrx command is an replacement of “
tar
-zxvf” or “
tar -xjf” commands and
it provides a one single command to extract archives in a number of different
formats including
tar,
zip,
rpm,
deb,
gem,
7z,
cpio,
rar and many more. It can also used to decompress files
compressed with
bzip2,
gzip etc.
By default,
dtrx extract contents to a dedicated directory
and also fixes permission issues (like
permission denied)
faced by user while extracting content to ensure that the owner can read and
write all those files.
Dtrx Features
- Handles
many archive types: It provides only one simple command to
extract tar, zip, rar, gz, bz2, xz, rpm, deb, gem, self-extracting zip
files and many other formats of exe files.
- Keeps
everything organized: It will extract archives into their
own dedicated directories.
- Sane
permissions: It also make sure, user can read and write
all those files after extraction, keeping permission intact.
- Recursive
extraction: It can find archives inside the archive and
extract those too.
How to Install Dtrx in Linux
The dtrx tool is by default included in
Ubuntu
repositories, all you’ve to do is simple do a
apt-get to
install in on your system.
On Debian/Ubuntu/Linux Mint
$ sudo apt-get install dtrx
On RHEL/CentOS/Fedora
On Red Hat based systems,
dtrx is not available via default
repositories, you need to download a dtrx script and install the program
system-wide using below commands as
root user.
# wget http://brettcsmith.org/2007/dtrx/dtrx-7.1.tar.gz
# tar -xvf dtrx-7.1.tar.gz
# cd dtrx-7.1
# python setup.py install --prefix=/usr/local
Sample Output
running install
running build
running build_scripts
creating build
creating build/scripts-2.6
copying and adjusting scripts/dtrx -> build/scripts-2.6
changing mode of build/scripts-2.6/dtrx from 644 to 755
running install_scripts
copying build/scripts-2.6/dtrx -> /usr/local/bin
changing mode of /usr/local/bin/dtrx to 755
running install_egg_info
Creating /usr/local/lib/python2.6/site-packages/
Writing /usr/local/lib/python2.6/site-packages/dtrx-7.1-py2.6.egg-info
How to Use dtrx Command
The dtrx command is sort of like the one ring to rule them all in the
Lord
of The Rings. Instead of having to remember syntax for each archive,
all you have to remember is dtrx command.
1. Extracting Single Archive
For example, I want to extract a archive file called “
tecmint27-12-2013.gz“,
I only execute dtrx command without using any flags.
[root@tecmint]# dtrx tecmint27-12-2013.gz
Other than simplifying the extraction, it has a bunch of other options like
extracting the file to a folder and recursively extracting all other archives
inside a given archive.
2. Extracting Multiple Archives
Consider you’ve a file “
dtrAll.zip“,
consisting of
dtr1.zip,
dtr2.zip and
dtr3.zip
each consisting of
dtr1,
dtr2 and
dtr3
respectively. Instead of having to manually first extract the
dtrAll
zip and then extracting each one of the
dtr1,
dtr2
and
dtr3 you can directly extract it in respective folders by
using dtrx and by selecting option “
a“, it
extracts all the zip files recursively.
[root@tecmint]# dtrx dtrAll.zip
Sample Output
dtrx: WARNING: extracting /root/dtrAll.zip to dtrAll.1
dtrAll.zip contains 3 other archive file(s), out of 3 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) a
After, extraction, the contents of the extracted directory can be verified
using
ls command.
[root@tecmint]# cd dtrAll
[root@tecmint]# ls
dtr1 dtr1.zip dtr2 dtr2.zip dtr3 dtr3.zip
3. Extracting Specific Archive
Let’s say you want to extract the first archive and not archives
inside it. By selecting
N, it only extracts the given archive
and not other archives inside it.
[root@tecmint]# dtrx dtrAll.zip
Sample Output
dtrx: WARNING: extracting /root/dtrAll.zip to dtrAll.1
dtrAll.zip contains 3 other archive file(s), out of 3 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) N
The contents of extracted directory can be verified using ls command as
shown.
[root@tecmint]# cd dtrAll
[root@tecmint]# ls
dtr1.zip dtr2.zip dtr3.zip
4. Extract Each Layer of Archive
To extract each layer of archive inside archive on a case by case basis
i.e., if you want to extract 2nd layer of archives but not the 3rd layer, you
can use the “
o” option.
Consider you’ve a zip file “
dtrNewAll.zip“,
which has “
dtrAll.zip” and “
dtrNew”
as it’s contents. Now if you want to extract the contents of “
dtrNewAll”
and “
dtrAll” as well but not of
dtr1.zip,
dtr2.zip and
dtr3.zip, you can use “
o”
and “
n” options as shown below.
# dtrx dtrNewAll.zip
Sample Output
dtrNewAll.zip contains 1 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) o
dtrAll.zip contains 3 other archive file(s), out of 3 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) n
The contents of extracted directory can be verified using
ls
command as shown.
[root@tecmint]# cd dtrNewAll
[root@tecmint]# ls
dtrAll dtrAll.zip dtrNew
[root@tecmint]# cd dtrAll
[root@tecmint]# ls
dtr1.zip dtr2.zip dtr3.zip
We first select the “
o” option which means that
all archives inside
dtrNewAll will be extracted. Later we
select the “
n” option for
dtrAll.zip
which means that the archives inside it
dtr1.zip ,
dtr2.zip
and
dtr3.zip will not be extracted.
5. Extract meta-data from .deb, .rpm and .gem files
The “
-m” option extract the meta-data from
.deb,
.rpm and
.gem archives, instead of their
normal contents. Here is an example of the command.
[root@tecmint]# dtrx -m openfire_3.8.2_all.deb
[root@tecmint]# dtrx -m openfire-3.8.2-1.i386.rpm
[root@tecmint]# ls
conffiles control md5sums postinst postrm prerm
There are lot more dtrx options to explore, just run the “
dtrx
–help” to list the available options.
[root@tecmint]# dtrx --help
Usage: dtrx [options] archive [archive2 ...]
Intelligent archive extractor
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-l, -t, --list, --table list contents of archives on standard output
-m, --metadata extract metadata from a .deb/.gem
-r, --recursive extract archives contained in the ones listed
-n, --noninteractive don't ask how to handle special cases
-o, --overwrite overwrite any existing target output
-f, --flat, --no-directory extract everything to the current directory
-v, --verbose be verbose/print debugging information
-q, --quiet suppress warning/error messages