如何使用packages.ubuntu.com像apt-file搜索不同的版本?

我想从命令行使用http://packages.ubuntu.com/的强大function,类似于apt-file search -i工作,以查找提供包含特定模式的文件的包。

我不能使用apt-file因为我不仅需要搜索我正在运行的版本(14.04),还要搜索14.10和15.04。

我如何获得所有提供包含com.canonical.Unity glib-2.0模式的com.canonical.Unity但是如果我从命令行运行14.04则为14.10?

  1. 安装html2text

     sudo apt-get install html2text 
  2. 将以下函数粘贴到.bashrc

     apt-file-remote() { pattern="$1" release="$2" if [ -z "$release" ]; then release="$(lsb_release -c -s)" fi wget "http://packages.ubuntu.com/search?searchon=contents&keywords=$pattern&mode=filename&suite=$release" -qO- | html2text -width 999 | grep --color=never '^/' } 
  3. 重新启动shell或打开一个新终端

使用模式作为第一个参数然后释放代码名称(可选,默认为当前版本)运行它:

 $ apt-file-remote com.canonical.unity utopic /etc/dbus-1/system.d/com.canonical.Unity.Greeter.Broadcast.conf unity-greeter-session-broadcast [...] /usr/share/glib-2.0/schemas/com.canonical.Unity.Thumbnailer.gschema.xml thumbnailer-service /usr/share/glib-2.0/schemas/com.canonical.Unity.gschema.xml unity-schemas /usr/share/glib-2.0/schemas/com.canonical.unity-greeter.gschema.xml unity-greeter /usr/share/glib-2.0/schemas/com.canonical.unity-gtk-module.gschema.xml unity-gtk-module-common /usr/share/glib-2.0/schemas/com.canonical.unity.clickscope.gschema.xml unity-scope-click /usr/share/glib-2.0/schemas/com.canonical.unity.webapps.gschema.xml unity-webapps-service /var/lib/polkit-1/localauthority/10-vendor.d/com.canonical.unity.webapps.pkla unity-webapps-common 

感谢这个function,我发现:

 /usr/share/glib-2.0/schemas/com.canonical.Unity.Thumbnailer.gschema.xml 

仅在Utopic上安装。

笔记:

  • 我使用html2text -width 999默认情况下html2text使用80列渲染输出,这可能会将某些名称分成2行。
  • 它实际上比本地apt-file search -i更快