Debian apt系命令小技巧
在使用apt命令时的一些技巧。假设已经了解安装和基本使用方法。
超级牛力
$ apt moo
$ apt moo moo
$ apt moo moo moo
# 4つめ以降は上の3つがランダムで出現
想知道可安装的版本。
使用apt list -a。
$ apt list -a weston
一覧表示... 完了
weston/testing,unstable 3.0.0-1 amd64 [1.12.0-3 からアップグレード可]
weston/now 1.12.0-3 amd64 [インストール済み、3.0.0-1 にアップグレード可]
可以使用glob模式
$ apt list -a 'libwayland*'
一覧表示... 完了
libwayland-bin/testing,unstable,now 1.14.0-1 amd64 [インストール済み、自動]
libwayland-client0/testing,unstable,now 1.14.0-1 amd64 [インストール済み、自動]
libwayland-client0/不明 1.6.0-2 amd64
libwayland-cursor0/testing,unstable,now 1.14.0-1 amd64 [インストール済み、自動]
libwayland-cursor0/不明 1.6.0-2 amd64
# 以下省略
我想要安装特定的版本。
$ apt list -a weston
一覧表示... 完了
weston/testing,unstable 3.0.0-1 amd64 [1.12.0-3 からアップグレード可]
weston/now 1.12.0-3 amd64 [インストール済み、3.0.0-1 にアップグレード可]
如果是这样的情况
$ sudo apt install weston/testing
或者
$ sudo apt install weston=3.0.0-1
可以指定版本。
查找文件包含在哪个软件包中。
使用apt-file
$ apt-file search weston.ini
weston: /usr/share/doc/weston/examples/weston.ini
weston: /usr/share/man/man5/weston.ini.5.gz
可以在x中使用正则表达式。
$ apt-file search -x 'weston\.ini\.[0-9]'
weston: /usr/share/man/man5/weston.ini.5.gz
展示包的依赖关系
使用apt rdepends
$ apt rdepends libwayland-client0
libwayland-client0
Reverse Depends:
依存: libweston-3-0 (>= 1.11.91)
依存: libegl1-mesa (>= 1.9.91)
依存: libmutter0f (>= 1.5.90)
依存: mpv (>= 1.9.91)
依存: xwayland (>= 1.9.91)
依存: gstreamer1.0-vaapi (>= 1.9.91)
# 以下省略
仅使用软件包名称进行 apt search 匹配
使用apt search命令时,默认会搜索包括描述在内的所有内容。
如果要停止这一行为,只需在命令后面添加–names-only选项即可。
$ apt search --names-only compositor
# 以下省略
我想了解包中包含的文件。
使用dpkg -L命令
$ dpkg -L libdrm-dev
/.
/usr
/usr/include
/usr/include/libdrm
/usr/include/libdrm/amdgpu.h
/usr/include/libdrm/amdgpu_drm.h
/usr/include/libdrm/drm.h
# 以下省略
用脚本来使用apt不好吗?
当将apt的输出与管道连接时,可以
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
被警告