如何自定义Ubuntu下whereis命令的输出格式

   2024-09-30 5390
核心提示:whereis 命令在 Ubuntu 系统中用于查找文件,它会显示二进制文件、源代码文件和手册页的位置使用 alias 命令为 wherei

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/bashif [ $# -eq 0 ]; then    echo "Usage: custom_whereis<command>"    exit 1ficommand=$1binary=$(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/lsManpage: /usr/share/man/man1/ls.1.gzSource: /usr/src/linux-headers-5.4.0-70/include/config/ls.h

这些方法可以帮助你根据需要自定义 whereis 命令的输出格式。

 
举报打赏
 
更多>同类物流大全
推荐图文
推荐物流大全
点击排行

网站首页  |  关于我们  |  联系方式网站留言    |  赣ICP备2021007278号