为什么我在 apt 缓存中搜索“git”时得到如此多的点击?

为什么我在 apt 缓存中搜索“git”时得到如此多的点击?

当我发出以下命令时:

 apt-cache search git | wc -l

我得到的答案是 756。我怎样才能列出与 git 相关的六个左右的应用程序?

答案1

使用锚点搜索 ( ^...)

您可以像这样搜索以字符串“git”开头的条目。

例子

$ apt-cache search ^git | head -10
git - fast, scalable, distributed revision control system
git-core - fast, scalable, distributed revision control system (obsolete)
git-doc - fast, scalable, distributed revision control system (documentation)
git-man - fast, scalable, distributed revision control system (manual pages)
gitk - fast, scalable, distributed revision control system (revision tree visualizer)
easygit - git for mere mortals
gforge-plugin-scmgit - Git plugin for FusionForge (transitional package)
git-all - fast, scalable, distributed revision control system (all subpackages)
git-annex - manage files with git, without checking their contents into git
git-arch - fast, scalable, distributed revision control system (arch interoperability)

这与仅搜索字符串“git”有细微的区别,但区别在于此搜索将找到以字符串“git”开头的子字符串,而对“git”的裸字搜索将返回诸如“digital”之类的条目。

apt-cache search ^git您还可以通过将输出通过管道传输到附加项来限制输出grep,如下所示:

使用 grep 过滤

$ apt-cache search ^git | grep "^git" | head -10
git - fast, scalable, distributed revision control system
git-core - fast, scalable, distributed revision control system (obsolete)
git-doc - fast, scalable, distributed revision control system (documentation)
git-man - fast, scalable, distributed revision control system (manual pages)
gitk - fast, scalable, distributed revision control system (revision tree visualizer)
git-all - fast, scalable, distributed revision control system (all subpackages)
git-annex - manage files with git, without checking their contents into git
git-arch - fast, scalable, distributed revision control system (arch interoperability)
git-buildpackage - Suite to help with Debian packages in Git repositories
git-cola - highly caffeinated git GUI

这只会显示名称以字符串“git”开头的包。

使用开关--names-only

这只会搜索包名称以查找以字符串“git”开头的匹配项。

$ apt-cache search --names-only ^git | head -10
git - fast, scalable, distributed revision control system
git-core - fast, scalable, distributed revision control system (obsolete)
git-doc - fast, scalable, distributed revision control system (documentation)
git-man - fast, scalable, distributed revision control system (manual pages)
gitk - fast, scalable, distributed revision control system (revision tree visualizer)
git-all - fast, scalable, distributed revision control system (all subpackages)
git-annex - manage files with git, without checking their contents into git
git-arch - fast, scalable, distributed revision control system (arch interoperability)
git-buildpackage - Suite to help with Debian packages in Git repositories
git-cola - highly caffeinated git GUI

答案2

最有可能是因为这个:

apt-cache show libqt5sensors5 | grep -i git
Version: 5.0~git20130507-0ubuntu1~raring1~test1
 WARNING: This module is not an official part of Qt 5, but instead a git
Version: 5.0~git20130115-0ubuntu1
Filename: pool/universe/q/qtsensors-opensource-src/libqt5sensors5_5.0~git20130115-0ubuntu1_amd64.deb

有些包与“git”相关,有些包只是在描述中的某处有“git”,因为apt-cache search不仅在包名称中搜索,而且在短/长描述中搜索。

我怎样才能列出与 git 相关的六个左右的应用程序?

apt-cache search git | grep -i git

这将只显示简短描述或包名称中包含“git”的包。

相关内容