whereis 命令在 Ubuntu 系统中用于查找文件,它会显示二进制文件、源代码文件和手册页的位置
alias 命令为 whereis 创建一个自定义别名。这样,当你输入自定义别名时,实际上会运行修改后的 whereis 命令。打开终端并输入以下命令:alias mywhereis="whereis -b -m -s" 这将创建一个名为 mywhereis 的别名,它只显示二进制文件(-b)、手册页(-m)和源代码文件(-s)的位置。要使这个别名永久生效,请将上述命令添加到 ~/.bashrc 或 ~/.bash_aliases 文件中。
grep 过滤 whereis 命令的输出。例如,如果你只想查看二进制文件的位置,可以使用以下命令:whereis ls | grep "ls:" 这将只显示与 ls 相关的二进制文件信息。
custom_whereis.sh 的脚本,内容如下:#!/bin/bash if [ $# -eq 0 ]; then echo "Usage: custom_whereis<command>" exit 1 fi command=$1 binary=$(whereis -b $command | awk '{print $2}') manpage=$(whereis -m $command | awk '{print $2}') source=$(whereis -s $command | awk '{print $2}') echo "Binary: $binary" echo "Manpage: $manpage" echo "Source: $source" 给脚本执行权限:
chmod +x custom_whereis.sh 然后运行脚本:
./custom_whereis.sh ls 这将显示类似于以下内容的输出:
Binary: /bin/ls Manpage: /usr/share/man/man1/ls.1.gz Source: /usr/src/linux-headers-5.4.0-70/include/config/ls.h 这些方法可以帮助你根据需要自定义 whereis 命令的输出格式。