dtrx – The Universal Archive Extractor For Many Archive Types
The dtrx tool is an universal archive extractor for many archive types. dtrx stands for “Do The Right Extraction”. It is a free, open source archive extraction tool. You don’t need to have multiple extraction tools for handling different types of archive files. dtrx will take care of almost all types of archive files such as tar, zip, cpio, deb, rpm, gem, 7z, cab, lzh, rar, gz, bz2, lzma, xz, and many kinds of exe files, including Microsoft Cabinet archives, InstallShield archives, and self-extracting zip files. dtrx will extract the archives into their own dedicated directories. Also, it makes sure you can read and write all the files you just extracted, while leaving the rest of the permissions intact. Further more, it can find the archives inside the archive and extract them too.
In this brief tutorial, we will see how to install and use dtrx for handling archive files in Unix-like operating systems.
dtrx – Intelligent Archive Extraction Utility
On Arch LInux and its derivatives:
$ yaourt -S dtrx
$ packer -S dtrx
On Ubuntu and its derivatives:
The dtrx extraction tool is available in the default repositories of Ubuntu. The following command will install dtrx on your Ubuntu system.
$ sudo apt-get install dtrx
On other Linux distributions, you can manually compile and install it from the source as shown below.
Make sure you have installed python in your Linux box. Then, download the latest version from here.
$ wget https://brettcsmith.org/2007/dtrx/dtrx-7.1.tar.gz
Extract the downloaded archive file using command:
$ tar -xvf dtrx-7.1.tar.gz
GO to the folder where you extracted dtrx.
$ cd dtrx-7.1
Finally, compile and install it as shown below.
$ python setup.py install --prefix=/usr/local
Unlike other archive extractors, you don’t need to remember all options and arguments. Just use dtrx command followed by the archive file as shown below.
$ dtrx dir1.tar
Where, dir1.tar is the tar archive file.
It will extract all all contents of dir1.tar archive into a folder called dir1 in the current working directory. You don’t need to install tar archiving utility or don’t need to know how to use tar command to extract archives. dtr will extract the given file, no matter which archive format the file is.
Now, consider another archive file called dir2.zip that consists of archive files namely file1.tar and file2.bz2. Let us extract it using command:
$ dtrx dir2.zip
dtrx is smart enough to find and tell you that dir2.zip file contains two other archives in it. And, it will give you list of suggestions to do.
As you see in the above output, you can choose any one of the following actions by entering the relevant letters given below.
- a – Extract the archive file and all other included archive files recursively.
- o – Extract included archive files this once.
- N – Do not extract included archive files. It means that this option will only extract the source archive file, not other archives inside of it.
- v – Never extract included archive files during this session.
- l – List all included archives.
You can also extract multiple files at once by specifying space separated archives as shown below.
$ dtrx dir1.tar dir2.zip dir3.tar.bz2
Again, if an archive file contains other archives inside it, you will be asked the above questions. Press any letter to perform the respective operation.
It is also possible to extract the metadata from a .deb or .gem files. The -m option will only extract the metadata from those files, not the whole content.
$ dtrx -m python_2.7.9-1_amd64.deb
To view the metadata of the abve file, just use ls command.
$ ls python_2.7.9-1/ control md5sums postinst postrm preinst prerm
For more details, look at the help section by running the following command:
$ dtrx -h 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 --one=ONE_ENTRY_DEFAULT, --one-entry=ONE_ENTRY_DEFAULT specify extraction policy for one-entry archives: inside/rename/here -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
And, that’s all for now. Hope this helps. If you find our guides useful, be kind enough to share them on your social, professional networks and support OSTechNix.
More good stuffs to come. Stay tuned!