基于 Debian 的发行版的 15 个“dpkg 命令”实用示例
Debian GNU/Linux,许多 Linux 发行版(包括 Knoppix)的母体操作系统、Kali、Ubuntu、Mint等使用各种包管理器,如dpkg、apt 、能力、突触、tasksel、取消选择、dpkg-deb > 和dpkg-split。
在关注“dpkg”命令之前,我们将简要描述每一个命令。
APT命令
Apt代表高级打包工具。它不处理“deb”包并直接工作,但与“/etc/apt/”中指定位置的“deb”存档一起工作resources.list”文件。
了解更多:APT-GET 命令的 25 个有用的基本命令
资质
Aptitude 是 Debian 的基于文本的包管理器,它是“apt”的前端,使用户能够轻松管理包。
突触
图形化包管理器,即使是新手也能轻松安装、升级和卸载包。
塔塞尔
Tasksel 允许用户安装与特定任务(即桌面环境)相关的所有相关软件包。
取消选择
一个菜单驱动包管理工具,最初在第一次安装时使用,现在被aptitude取代。
Dpkg-deb
与 Debian 档案交互。
Dpkg 分割
可用于分割和合并大文件为小文件块,以便存储在较小尺寸的介质(如软盘)上。
dpkg命令
dpkg是Debian和基于Debian的系统中主要的包管理程序。它用于安装、构建、删除和管理软件包。 Aptitude 是 dpkg 的主要前端。
这里列出了一些最常用的 dpkg 命令及其用法:
1. 安装包
要安装“.deb”软件包,请使用带有“-i”选项的命令。例如,要安装名为“flashpluginnonfree_2.8.2+squeeze1_i386.deb”的“.deb”软件包,请使用以下命令。
[root@tecmint~]# dpkg -i flashpluginnonfree_2.8.2+squeeze1_i386.deb
Selecting previously unselected package flashplugin-nonfree.
(Reading database ... 465729 files and directories currently installed.)
Unpacking flashplugin-nonfree (from flashplugin-nonfree_3.2_i386.deb) ...
Setting up flashplugin-nonfree (1:3.2) ...
--2013-10-01 16:23:40-- http://fpdownload.macromedia.com/get/flashplayer/pdc/11.2.202.310/install_flash_player_11_linux.i386.tar.gz
Resolving fpdownload.macromedia.com (fpdownload.macromedia.com)... 23.64.66.70
Connecting to fpdownload.macromedia.com (fpdownload.macromedia.com)|23.64.66.70|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6923724 (6.6M) [application/x-gzip]
Saving to: ‘/tmp/flashplugin-nonfree.FPxQ4l02fL/install_flash_player_11_linux.i386.tar.gz’
2.列出所有已安装的软件包
要查看并列出所有已安装的软件包,请在命令中使用“-l”选项。
[root@tecmint~]# dpkg -l
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-======================================-========================-===============================================================================
ii accerciser 3.8.0-0ubuntu1 all interactive Python accessibility explorer for the GNOME desktop
ii account-plugin-aim 3.6.4-0ubuntu4.1 i386 Messaging account plugin for AIM
ii account-plugin-facebook 0.10bzr13.03.26-0ubuntu1 i386 GNOME Control Center account plugin for single signon - facebook
ii account-plugin-flickr 0.10bzr13.03.26-0ubuntu1 i386 GNOME Control Center account plugin for single signon - flickr
ii account-plugin-generic-oauth 0.10bzr13.03.26-0ubuntu1 i386 GNOME Control Center account plugin for single signon - generic OAuth
ii account-plugin-google 0.10bzr13.03.26-0ubuntu1 i386 GNOME Control Center account plugin for single signon
rc account-plugin-identica 0.10bzr13.03.26-0ubuntu1 i386 GNOME Control Center account plugin for single signon - identica
ii account-plugin-jabber 3.6.4-0ubuntu4.1 i386 Messaging account plugin for Jabber/XMPP
....
要查看已安装或未安装的特定软件包,请使用选项“-l”和软件包名称。例如,检查apache2软件包是否已安装。
[root@tecmint~]# dpkg -l apache2
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-======================================-========================-==============================================
ii apache2 2.2.22-6ubuntu5.1 i386 Apache HTTP Server metapackage
3. 删除包
要删除“.deb”包,我们必须指定包名称“flashpluginnonfree”,而不是原始名称“flashplugin-nonfree_3.2_i386.deb”强>“。 “-r”选项用于删除/卸载软件包。
[root@tecmint~]# dpkg -r flashpluginnonfree
(Reading database ... 142891 files and directories currently installed.)
Removing flashpluginnonfree ...
Processing triggers for man-db ...
Processing triggers for menu ...
Processing triggers for desktop-file-utils ...
Processing triggers for gnome-menus ...
您还可以使用“p”选项代替“r”,这将删除包以及配置文件。 ‘r’选项只会删除软件包,不会删除配置文件。
[root@tecmint~]# dpkg -p flashpluginnonfree
4. 查看包内容
要查看特定包的内容,请使用“-c”选项,如图所示。该命令将以长列表格式显示“.deb”包的内容。
[root@tecmint~]# dpkg -c flashplugin-nonfree_3.2_i386.deb
drwxr-xr-x root/root 0 2012-12-14 22:54 ./
drwxr-xr-x root/root 0 2012-12-14 22:54 ./usr/
drwxr-xr-x root/root 0 2012-12-14 22:54 ./usr/bin/
drwxr-xr-x root/root 0 2012-12-14 22:54 ./usr/lib/
drwxr-xr-x root/root 0 2012-12-14 22:54 ./usr/lib/mozilla/
drwxr-xr-x root/root 0 2012-12-14 22:54 ./usr/lib/mozilla/plugins/
drwxr-xr-x root/root 0 2012-12-14 22:54 ./usr/lib/flashplugin-nonfree/
-rw-r--r-- root/root 3920 2009-09-09 22:51 ./usr/lib/flashplugin-nonfree/pubkey.asc
drwxr-xr-x root/root 0 2012-12-14 22:54 ./usr/share/
drwxr-xr-x root/root 0 2012-12-14 22:54 ./usr/share/man/
drwxr-xr-x root/root 0 2012-12-14 22:54 ./usr/share/man/man8/
-rw-r--r-- root/root 716 2012-12-14 22:54 ./usr/share/man/man8/update-flashplugin-nonfree.8.gz
drwxr-xr-x root/root 0 2012-12-14 22:54 ./usr/share/applications/
drwxr-xr-x root/root 0 2012-12-14 22:54 ./usr/share/icons/
drwxr-xr-x root/root 0 2012-12-14 22:54 ./usr/share/icons/hicolor/
drwxr-xr-x root/root 0 2012-12-14 22:54 ./usr/share/icons/hicolor/24x24/
....
5. 检查软件包是否安装
使用“-s”选项和软件包名称,将显示 deb 软件包是否已安装。
[root@tecmint~]# dpkg -s flashplugin-nonfree
Package: flashplugin-nonfree
Status: install ok installed
Priority: optional
Section: contrib/web
Installed-Size: 177
Maintainer: Bart Martens <[email >
Architecture: i386
Version: 1:3.2
Replaces: flashplugin (<< 6)
Depends: debconf | debconf-2.0, wget, gnupg, libatk1.0-0, libcairo2, libfontconfig1, libfreetype6, libgcc1, libglib2.0-0, libgtk2.0-0 (>= 2.14), libnspr4, libnss3, libpango1.0-0, libstdc++6, libx11-6, libxext6, libxt6, libcurl3-gnutls, binutils
Suggests: iceweasel, konqueror-nsplugins, ttf-mscorefonts-installer, ttf-dejavu, ttf-xfree86-nonfree, flashplugin-nonfree-extrasound, hal
Conflicts: flashplayer-mozilla, flashplugin (<< 6), libflash-mozplugin, xfs (<< 1:1.0.1-5)
Description: Adobe Flash Player - browser plugin
...
6.检查安装包的位置
列出要从包名称安装到系统的文件的位置。
[root@tecmint~]# dpkg -L flashplugin-nonfree
/.
/usr
/usr/bin
/usr/lib
/usr/lib/mozilla
/usr/lib/mozilla/plugins
/usr/lib/flashplugin-nonfree
/usr/lib/flashplugin-nonfree/pubkey.asc
/usr/share
/usr/share/man
/usr/share/man/man8
/usr/share/man/man8/update-flashplugin-nonfree.8.gz
/usr/share/applications
/usr/share/icons
/usr/share/icons/hicolor
...
7. 安装目录中的所有软件包
递归地安装在指定目录及其所有子目录中找到的与模式“*.deb”匹配的所有常规文件。这可以与“-R”和“-install”选项一起使用。例如,我将安装名为“debpackages”的目录中的所有“.deb”软件包。
[root@tecmint~]# dpkg -R --install debpackages/
(Reading database ... 465836 files and directories currently installed.)
Preparing to replace flashplugin-nonfree 1:3.2 (using .../flashplugin-nonfree_3.2_i386.deb) ...
Unpacking replacement flashplugin-nonfree ...
Setting up flashplugin-nonfree (1:3.2) ...
Processing triggers for man-db ...
Processing triggers for bamfdaemon ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for gnome-menus ...
8.解压包但不进行配置
使用操作“–unpack”将解压软件包,但不会安装或配置它。
[root@tecmint~]# dpkg --unpack flashplugin-nonfree_3.2_i386.deb
(Reading database ... 465836 files and directories currently installed.)
Preparing to replace flashplugin-nonfree 1:3.2 (using flashplugin-nonfree_3.2_i386.deb) ...
Unpacking replacement flashplugin-nonfree ...
Processing triggers for man-db ...
Processing triggers for bamfdaemon ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for gnome-menus ...
9. 重新配置解压后的包
选项“-configure”将重新配置已经解压的包。
[root@tecmint~]# dpkg --configure flashplugin-nonfree
Setting up flashplugin-nonfree (1:3.2) ...
10.替换可用的包信息
“–-update-avail”选项将旧信息替换为 Packages 文件中的可用信息。
[root@tecmint~]# dpkg –-update-avail package_name
11. 删除包现有的可用信息
“–clear-avaial”操作将删除有关可用软件包的当前信息。
[root@tecmint~]# dpkg –-clear-avail
12.忘记已卸载和不可用的软件包
带有选项“--forget-old-unavail”的 dpkg 命令将自动忘记已卸载和不可用的软件包。
[root@tecmint~]# dpkg --forget-old-unavail
13.显示dpkg许可证
[root@tecmint~]# dpkg --licence
14.显示dpkg版本
“–version”参数将显示 dpkg 版本信息。
[root@tecmint~]# dpkg –version
Debian `dpkg' package management program version 1.16.10 (i386).
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
15. 获取有关 dpkg 的所有帮助
“-help”选项将显示 dpkg 命令的可用选项列表。
[root@tecmint~]# dpkg –help
Usage: dpkg [<option> ...] <command>
Commands:
-i|--install <.deb file name> ... | -R|--recursive <directory> ...
--unpack <.deb file name> ... | -R|--recursive <directory> ...
-A|--record-avail <.deb file name> ... | -R|--recursive <directory> ...
--configure <package> ... | -a|--pending
--triggers-only <package> ... | -a|--pending
-r|--remove <package> ... | -a|--pending
-P|--purge <package> ... | -a|--pending
--get-selections [<pattern> ...] Get list of selections to stdout.
--set-selections Set package selections from stdin.
--clear-selections Deselect every non-essential package.
--update-avail <Packages-file> Replace available packages info.
--merge-avail <Packages-file> Merge with info from file.
--clear-avail Erase existing available info.
--forget-old-unavail Forget uninstalled unavailable pkgs.
-s|--status <package> ... Display package status details.
...
目前为止就这样了。我很快就会再次在这里发表另一篇有趣的文章。如果我错过了列表中的任何命令,请通过评论告诉我。在那之前,请继续关注并保持与 Howtoing 的联系。喜欢并分享我们并帮助我们传播。不要忘记在评论中提及您的宝贵想法。