一个应用程序通常包含 3 种不同的文件类型:
- 二进制文件
- 配置文件
- 应用数据
Linux(例如 CentOS、RHEL)在哪里存储给定应用程序的二进制文件?我怎样才能找到它以进行应用程序?
答案1
您可以用于whereis
此任务。
$ whereis python3
python3: /usr/bin/python3.5m /usr/bin/python3 /usr/bin/python3.5 /usr/lib/python3 /usr/lib/python3.5 /etc/python3 /usr/local/lib/python3.5 /usr/share/python3 /usr/share/man/man1/python3.1.gz
答案2
要查找二进制文件本身,另一种方法是type
.
$ type python3
python3 is /usr/bin/python3
$
就配置文件和数据文件的位置而言,确定它们的最佳位置通常是相关man
页面。
$ man python3 | grep -A10 FILES
FILES AND DIRECTORIES
These are subject to difference depending on local installation conven‐
tions; ${prefix} and ${exec_prefix} are installation-dependent and
should be interpreted as for GNU software; they may be the same. The
default for both is /usr/local.
${exec_prefix}/bin/python
Recommended location of the interpreter.
${prefix}/lib/python<version>
${exec_prefix}/lib/python<version>
$
答案3
您可以尝试which
像这样使用:
$ which zoom
/usr/bin/zoom
这可能是一个符号链接,因此要找到实际的真实路径
ls -la $(which zoom)
lrwxrwxrwx 1 root root 22 Apr 24 07:19 /usr/bin/zoom -> /opt/zoom/ZoomLauncher
答案4
Shell脚本what-about
我使用 shellscriptwhat-about
来显示可执行程序的一些基本信息,这些信息可以通过PATH
,
- 它位于哪里
- 它属于哪个包或可以从哪个包安装
- 它是什么类型的程序(二进制可执行代码、shellscript、shell 内置、别名、链接...)
该shellscript 使用属于 Debian 和 Ubuntu 的bash
工具,也可以在从这两个发行版开发的 Linux 发行版中使用。dpkg
如果你想查看一个[debian]程序包的全部内容,你可以使用dpkg
或emacs
根据这个链接到 AskUbuntu。
如果你想在其他发行版中找到该程序所属的程序包,原问题中提到了CentOS和RHEL,则必须替换dpkg
为相应的工具。
这里是:
#!/bin/bash
LANG=C
inversvid="\0033[7m"
resetvid="\0033[0m"
if [ $# -ne 1 ]
then
echo "Usage: ${0##*/} <program-name>"
echo "Will try to find corresponding package"
echo "and tell what kind of program it is"
exit 1
fi
command="$1"
str=;for ((i=1;i<=$(tput cols);i++)) do str="-$str";done
tmp="$command"
first=true
curdir="$(pwd)"
tmq=$(which "$command")
tdr="${tmq%/*}"
tex="${tmq##*/}"
if test -d "$tdr"; then cd "$tdr"; fi
#echo "cwd='$(pwd)' ################# d"
while $first || [ "${tmp:0:1}" == "l" ]
do
first=false
tmp=${tmp##*\ }
tmq="$tmp"
tmp=$(ls -l "$(which "$tmp")" 2>/dev/null)
tdr="${tmq%/*}"
tex="${tmq##*/}"
if test -d "$tdr"; then cd "$tdr"; fi
# echo "cwd='$(pwd)' ################# d"
if [ "$tmp" == "" ]
then
tmp=$(ls -l "$tex" 2>/dev/null)
tmp=${tmp##*\ }
if [ "$tmp" == "" ]
then
echo "$command is not in PATH"
# package=$(bash -ic "$command -v 2>&1")
# echo "package=$package XXXXX 0"
bash -ic "alias '$command' > /dev/null 2>&1" > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo 'looking for package ...'
package=$(bash -ic "$command -v 2>&1"| sed -e '0,/with:/d'| grep -v '^$')
else
echo 'alias, hence not looking for package'
fi
# echo "package=$package XXXXX 1"
if [ "$package" != "" ]
then
echo "$str"
echo "package: [to get command '$1']"
echo -e "${inversvid}${package}${resetvid}"
fi
else
echo "$tmp"
fi
else
echo "$tmp"
fi
done
tmp=${tmp##*\ }
if [ "$tmp" != "" ]
then
echo "$str"
program="$tex"
program="$(pwd)/$tex"
file "$program"
if [ "$program" == "/usr/bin/snap" ]
then
echo "$str"
echo "/usr/bin/snap run $command # run $command "
sprog=$(find /snap/"$command" -type f -iname "$command" \
-exec file {} \; 2>/dev/null | sort | tail -n1)
echo -e "${inversvid}file: $sprog$resetvid"
echo "/usr/bin/snap list $command # list $command"
slist="$(/usr/bin/snap list "$command")"
echo -e "${inversvid}$slist$resetvid"
else
package=$(dpkg -S "$program")
if [ "$package" == "" ]
then
package=$(dpkg -S "$tex" | grep -e " /bin/$tex$" -e " /sbin/$tex$")
if [ "$package" != "" ]
then
ls -l /bin /sbin
fi
fi
if [ "$package" != "" ]
then
echo "$str"
echo " package: /path/program [for command '$1']"
echo -e "${inversvid} $package ${resetvid}"
fi
fi
fi
echo "$str"
#alias=$(grep "alias $command=" "$HOME/.bashrc")
alias=$(bash -ic "alias '$command' 2>/dev/null"| grep "$command")
if [ "$alias" != "" ]
then
echo "$alias"
fi
type=$(type "$command" 2>/dev/null)
if [ "$type" != "" ]
then
echo "type: $type"
elif [ "$alias" == "" ]
then
echo "type: $command: not found"
fi
cd "$curdir"
该 shellscript 可以找到一个链接或一系列链接“后面”的程序。
也可以看看这个链接到 AskUbuntu,其中有一些演示示例。