网站搜索

Dtrx - 适用于 Linux 的智能存档提取(tar、zip、cpio、rpm、deb、rar)工具


我们所有人在使用 Linux tar.gztar.bz2tbz 命令时都可能在某个时间点遇到过这种情况。如此多的存档类型,如此多的命令要记住......好吧,不再是了,感谢 dtrx 工具。

  1. 在 Linux 中创建和提取档案的 18 个 Tar 命令
  2. 如何在 Linux 中打开、解压和创建 RAR 文件

什么是 Dtrx?

Dtrx 代表“Do The Right Extraction”,它是一个开源且非常有效的 *nix 系统命令行应用程序,可以更轻松地简化您的存档提取工作。

dtrx 命令是“tar -zxvf”或“tar -xjf”命令的替代品,它提供了一个命令来提取档案有多种不同的格式,包括 tarziprpmdebgem >、7zcpiorar 等等。它还可以用于解压缩使用bzip2gzip等压缩的文件。

默认情况下,dtrx将内容提取到专用目录,并修复用户在提取内容时遇到的权限问题(例如权限被拒绝),以确保所有者可以读取和写入所有内容那些文件。

Dtrx 特点

  1. 处理多种存档类型:它仅提供一个简单的命令来提取 tar、zip、rar、gz、bz2、xz、rpm、deb、gem、自解压 zip 文件和许多其他格式的 exe 文件。
  2. 让一切井井有条:它将把档案提取到它们自己的专用目录中。
  3. 健全的权限:它还确保用户在提取后可以读取和写入所有这些文件,保持权限完整。
  4. 递归提取:它可以在存档中找到存档并提取它们。

如何在 Linux 中安装 Dtrx

dtrx 工具默认包含在 Ubuntu 存储库中,您所要做的就是简单地执行 apt-get 安装在您的系统上。

在 Debian/Ubuntu/Linux Mint 上

sudo apt-get install dtrx

在 RHEL/CentOS/Fedora 上

在基于 Red Hat 的系统上,dtrx 无法通过默认存储库使用,您需要下载 dtrx 脚本并以 root 用户身份使用以下命令在系统范围内安装该程序。

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
样本输出
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

如何使用 dtrx 命令

dtrx 命令有点像指环王中统治它们的一个戒指。您不必记住每个存档的语法,只需记住 dtrx 命令即可。

1. 提取单个档案

例如,我想提取一个名为“howtoing27-12-2013.gz”的存档文件,我只执行 dtrx 命令而不使用任何标志。

[root@tecmint]# dtrx tecmint27-12-2013.gz

除了简化提取之外,它还有许多其他选项,例如将文件提取到文件夹以及递归提取给定存档内的所有其他存档。

2. 提取多个档案

假设您有一个文件“dtrAll.zip”,其中包含 dtr1.zipdtr2.zipdtr3.zip< 每个分别由 dtr1dtr2dtr3 组成。不必先手动提取 dtrAll zip,然后再提取 dtr1dtr2dtr3 中的每一个您可以使用 dtrx 直接将其解压到相应的文件夹中,并选择选项“a”,它会递归地解压所有 zip 文件。

[root@tecmint]# dtrx dtrAll.zip
样本输出
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

解压后,可以使用ls命令验证解压目录的内容。

[root@tecmint]# cd dtrAll
[root@tecmint]# ls 

dtr1  dtr1.zip  dtr2  dtr2.zip  dtr3  dtr3.zip

3. 提取特定档案

假设您想要提取第一个存档而不是其中的存档。通过选择N,它仅提取给定的存档,而不提取其中的其他存档。

[root@tecmint]# dtrx dtrAll.zip
样本输出
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

可以使用 ls 命令验证提取的目录的内容,如下所示。

[root@tecmint]# cd dtrAll
[root@tecmint]# ls

dtr1.zip dtr2.zip dtr3.zip

4. 提取每一层存档

要根据具体情况提取档案内的每一层档案,即,如果您想提取第二层档案而不是第三层,您可以使用“o”选项。

假设您有一个 zip 文件“dtrNewAll.zip”,其内容为“dtrAll.zip”和“dtrNew”。现在,如果您还想提取“dtrNewAll”和“dtrAll”的内容,但不提取dtr1.zipdtr2的内容.zipdtr3.zip,您可以使用“o”和“n”选项,如下所示。

dtrx dtrNewAll.zip
样本输出
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

可以使用 ls 命令验证提取的目录的内容,如图所示。

[root@tecmint]# cd dtrNewAll
[root@tecmint]# ls

dtrAll  dtrAll.zip  dtrNew
[root@tecmint]# cd dtrAll
[root@tecmint]# ls

dtr1.zip dtr2.zip dtr3.zip

我们首先选择“o”选项,这意味着dtrNewAll内的所有档案都将被提取。稍后我们为 dtrAll.zip 选择“n”选项,这意味着其中的档案 dtr1.zipdtr2.zip dtr3.zip 将不会被提取。

5. 从 .deb、.rpm 和 .gem 文件中提取元数据

-m”选项从.deb.rpm.gem档案中提取元数据,而不是它们的正常内容。这是该命令的示例。

[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

还有更多 dtrx 选项可供探索,只需运行“dtrx –help”即可列出可用选项。

[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

参考链接

dtrx 主页

我认为您必须尝试dtrx,因为它是唯一强大的命令行工具,可以提供单个命令来解压缩任何格式的存档文件。现在就这样,别忘了在评论部分留下你的评论。