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

hjk*_*acs 3 regex ubuntu

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)
......
Run Code Online (Sandbox Code Playgroud)

hee*_*ayl 6

apt-cache search在给定的正则表达式模式下搜索程序包名称和描述,可以使正则表达式模式更可靠,并仅通过--names-only选项搜索程序包名称:

apt-cache search --names-only '^python3?-numpy'
Run Code Online (Sandbox Code Playgroud)

另外,您无需sudo运行apt-cache

  • ^python3?-numpy匹配程序包名称以python3-numpy或开头python-numpy

  • 如果只想搜索python3包装,请使用^python3-numpy

  • 只需获取软件包名称:

    apt-cache search --names-only '^python3?-numpy' | awk '{print $1}'
    
    Run Code Online (Sandbox Code Playgroud)

例:

$ 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
Run Code Online (Sandbox Code Playgroud)