由于官僚作风,我面临的情况是,我可以让某人在 Linux 服务器上运行 bash 脚本并给我输出,但我无法登录那里,或自己运行该脚本。
我相当确定有问题的服务器正在运行 Debian 或 Ubuntu。
我想找出安装了哪些版本python
和哪些g++
版本(长话短说)。
到目前为止,我最好的想法是获取$PATH
变量,将其分割:
,然后分别搜索所有路径以查找匹配的所有python
内容g++
。
有更明智的方法吗?
答案1
如果您没有本地安装 g++,以下内容应该适用于 g++。
dpkg -l 'g++*'
在我的系统上,这给出了:
dpkg -l 'g++*'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-================================-=====================-=====================-======================================================================
ii g++ 4:4.9.2-2 amd64 GNU C++ compiler
ii g++-4.6 4.6.3-14 amd64 GNU C++ compiler
un g++-4.6-multilib <none> <none> (no description available)
ii g++-4.9 4.9.2-10 amd64 GNU C++ compiler
ii g++-4.9-multilib 4.9.2-10 amd64 GNU C++ compiler (multilib files)
ii g++-multilib 4:4.9.2-2 amd64 GNU C++ compiler (multilib files)
对于 Python,类似的方法会出现太多误报,因为在 Debian 及其衍生版本上,所有 Python 库都以python-
.因此,人们需要一种更精致的全局模式。
就像是
dpkg -l 'python?.?'
应该管用。
dpkg -l 'python?.?'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-================================-=====================-=====================-======================================================================
ii python2.6 2.6.8-1.1 amd64 Interactive high-level object-oriented language (version 2.6)
ii python2.7 2.7.9-2 amd64 Interactive high-level object-oriented language (version 2.7)
un python3.1 <none> <none> (no description available)
ii python3.4 3.4.2-1 amd64 Interactive high-level object-oriented language (version 3.4)
答案2
和zsh
:
$ type -ma '(python|g++)*'
g++ is /usr/bin/g++
g++-4.4 is /usr/bin/g++-4.4
g++-4.6 is /usr/bin/g++-4.6
g++-5 is /usr/bin/g++-5
python is /usr/bin/python
python-config is /usr/bin/python-config
python-coverage is /usr/bin/python-coverage
python2 is /usr/bin/python2
python2-config is /usr/bin/python2-config
python2-coverage is /usr/bin/python2-coverage
python2-gflags2man is /usr/bin/python2-gflags2man
python2.7 is /usr/bin/python2.7
python2.7-config is /usr/bin/python2.7-config
python2.7-coverage is /usr/bin/python2.7-coverage
python3 is /usr/bin/python3
python3.2 is /usr/bin/python3.2
python3.2mu is /usr/bin/python3.2mu
python3.4 is /usr/bin/python3.4
python3.4m is /usr/bin/python3.4m
python3.5 is /usr/bin/python3.5
python3.5m is /usr/bin/python3.5m
python3m is /usr/bin/python3m
pythontex is /usr/bin/pythontex
pythontex3 is /usr/bin/pythontex3
类似type cmd
,但报告所有匹配该模式a
的命令(以及别名、函数和内置函数,如果用户的 shell 恰好是相关的zsh
) 。m
答案3
如果您想要 $PATH 中的版本,您可以运行:
python -V ; g++ --version
答案4
您可以使用which -a
搜索路径。
function get_versions {
for p in $(which -a $1); do
$p --version
done
}
get_versions python
get_versions g++