whereis与which命令核心差异概述
深入解析Linux系统中用于查找命令的whereis与which两个常用指令的核心差异。
whereis命令语法与功能说明
一、关于whereis命令
1、基础语法结构
使用格式为:whereis 命令名
该指令旨在检索指定命令的可执行文件存放位置,同时也会返回其对应的帮助文档(man page)所在路径。
常用选项包括:
-b:仅搜索可执行文件路径 -m:仅搜索帮助文件(man pages)路径
2、实际操作演示
[root@localhost ~]# whereis ls
ls:/usr/bin/ls /usr/share/man/man1/ls.1.gz/usr/share/man/man1p/ls.1p.gz
[root@localhost ~]# whoami
root
[root@localhost ~]# whatis
whatis what?
[root@localhost ~]# whatis ls
ls (1)- list directory contents
ls (1p)- list directory contents
[root@localhost ~]# whereis -b ls
ls:/usr/bin/ls
[root@localhost ~]# whereis -m ls
ls:/usr/share/man/man1/ls.1.gz/usr/share/man/man1p/ls.1p.gz
which命令语法与功能说明
二、关于which命令
1、基础语法结构
使用格式为:which 命令名
该指令主要用于在系统的PATH环境变量中搜索命令的执行文件路径,并且能够显示命令是否设置了别名。
2、实际操作演示
[root@localhost ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
[root@localhost ~]# which pwd
/usr/bin/pwd
[root@localhost ~]# whereis cd
cd:/usr/bin/cd /usr/share/man/man1/cd.1.gz/usr/share/man/man1p/cd.1p.gz
[root@localhost ~]# which cd
/usr/bin/cd
PATH环境变量在命令查找中的作用
三、PATH环境变量简介
PATH变量定义了系统在查找可执行命令时所要遍历的目录路径列表。
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
以上即为对Linux命令搜索工具whereis与which区别的详细讲解,如有疑问欢迎留言或前往社区交流讨论,共同进步。感谢阅读,希望本文能为您提供帮助,谢谢支持!