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

Tyl*_*den 4 apt package-management

当我给出以下命令时:

 apt-cache search git | wc -l
Run Code Online (Sandbox Code Playgroud)

我得到了 756 的答案。我如何只列出与 git 相关的六个左右的应用程序?

slm*_*slm 5

使用锚搜索 ( ^...)

您可以像这样搜索以字符串“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)
Run Code Online (Sandbox Code Playgroud)

这与仅搜索字符串“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
Run Code Online (Sandbox Code Playgroud)

这将只显示名称以字符串“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
Run Code Online (Sandbox Code Playgroud)