如何使用正则表达式在软件源中搜索特定软件包?【Ubuntu】

8

Ubuntu 14.04 LTS

我知道传统方法是使用sudo apt-cache search,但这并不是最好的方法。例如,如果我想搜索numpy,它会显示许多不相关的软件包,就像下面这样。我需要逐个搜索,有更好的方法吗?

.....
python3-tables-dbg - hierarchical database for Python 3 based on HDF5 (debug extension)
python3-tables-lib - hierarchical database for Python3 based on HDF5 (extension)
reinteract - Worksheet-based graphical Python shell
stimfit - Program for viewing and analyzing electrophysiological data
stimfit-dbg - Debug symbols for stimfit
texlive-lang-italian - TeX Live: Italian
python-spyderlib-doc - python IDE for scientists (Documentation)
python3-spyderlib - python IDE for scientists (Python 3)
spyder-common - python IDE for scientists (common files)
......
1个回答

12

apt-cache search 搜索给定的正则表达式模式匹配的软件包名称和描述,您可以通过 --names-only 选项使正则表达式模式更加健壮并仅搜索软件包名称:

apt-cache search --names-only '^python3?-numpy'

同时,运行 apt-cache 不需要使用 sudo 命令。

  • ^python3?-numpy 匹配以 python3-numpypython-numpy 开头的软件包名称。

  • 如果您只想在 python3 软件包中搜索,请使用 ^python3-numpy

  • 要仅获取软件包名称:

    apt-cache search --names-only '^python3?-numpy' | awk '{print $1}'
    

例子:

$ apt-cache search --names-only '^python3?-numpy'
python-numpy - Numerical Python adds a fast array facility to the Python language
python-numpy-dbg - Fast array facility to the Python language (debug extension)
python-numpy-doc - NumPy documentation
python3-numpy - Fast array facility to the Python 3 language
python3-numpy-dbg - Fast array facility to the Python 3 language (debug extension)
python-numpydoc - Sphinx extension to support docstrings in Numpy format

$ apt-cache search --names-only '^python3?-numpy' | awk '{print $1}'
python-numpy
python-numpy-dbg
python-numpy-doc
python3-numpy
python3-numpy-dbg
python-numpydoc

在某些情况下,我不知道确切的软件包名称是 python-numpy,我只知道 numpy,我该怎么办? - hjklemacs
如果你只知道部分内容,可以简单地搜索“numpy”,它将返回所有名称或描述中包含该内容的软件包。或者像上面那样,你可以用“*”替换“python3?”,这将搜索以“numpy”结尾的任何软件包。但在这种情况下,最好只进行“numpy”搜索。 - dragon788
apt search --names-only 也可以工作。 - Khalid Abu Shawarib

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接