【Linux学习笔记】7:命令搜索命令whereis与which
来源:互联网 发布:网络专业课程 编辑:程序博客网 时间:2024/06/16 02:15
命令搜索命令只能去搜索系统命令,而不能搜索那些我们自己建立的文件。
whereis搜索命令所在路径及帮助文档所在位置
whereis [-b -m] 命令名
选项:-b只查找执行文件,-m只查找帮助文件。
[root@bogon ~]# whereis lsls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
可以看到ls命令的执行文件是在/bin/下,所以它是所有用户都能执行的命令。后面的两个文件是它的帮助文档的绝对路径。
[root@bogon ~]# whereis -b lsls: /bin/ls[root@bogon ~]# whereis -m lsls: /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
which还能查看到命令的别名
[root@bogon ~]# which lsalias ls='ls --color=auto' /bin/ls
这说明ls命令支持颜色显示,它的颜色显示方案默认是auto(普通文件是黑的,目录文件是蓝的,执行文件是绿的等)。
不是所有的命令都有别名,对没有别名的命令,which就只能看到命令的执行文件的路径了。
[root@bogon ~]# which pwd/bin/pwd
不是所有的命令都能找到可执行文件,如用whereis来看一下cd命令。
[root@bogon ~]# whereis cdcd: /usr/share/man/man1/cd.1.gz /usr/share/man/man1p/cd.1p.gz
cd这样的命令是Linux的shell(Linux操作系统和用户交互所必须的东西)的内置命令,它是shell自带的,所以不需要在Linux系统中有执行文件。也就是说通过whereis与which看到的命令都是外部的。
用which也是找不到的,如下。
[root@bogon ~]# which cd/usr/bin/which: no cd in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
但是可以看到一堆目录,关于它的解释如下。
在Linux中要想执行路径,就需要绝对路径,本来执行ls是要这样写的:
[root@bogon ~]# /bin/lsanaconda-ks.cfg install.log install.log.syslog
但是这样很不方便,系统提供了一个叫PATH的环境变量(系统搜索命令的路径,用冒号分隔),当执行ls时,系统会去上面的路径中搜索是否有这样的脚本或执行文件,找到了就会执行它。用户通过设置环境变量,来更好的运行进程。
[root@bogon ~]# echo $PATH/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
因为有PATH的存在,所以系统命令是可以不打绝对路径的。如果是自己写的程序,执行时就需要绝对路径,否则就需要放在PATH所记录的路径中去。
阅读全文
0 0
- 【Linux学习笔记】7:命令搜索命令whereis与which
- Linux命令搜索命令whereis与which
- Linux命令搜索命令 whereis which
- 命令搜索命令whereis与which
- Linux学习笔记--whereis命令(搜索命令的命令)
- Linux学习之文件搜索命令(二)其他搜索命令 locate |which|whereis|grep
- Linux命令-whereis与which(查找文件)
- Centos之命令搜索命令whereis与which
- Linux学习笔记--which命令(搜索命令的命令)
- Linux 搜索命令(locate/find/whereis/which/grep)
- linux中文件搜索命令(whereis,locate,which,find)
- Linux 搜索命令:find,locate,whereis,which,type
- linux命令:文件搜索(locate、whereis、which、find、grep)
- Linxu命令与文件的搜索 - which, whereis, locate, find
- 搜索命令之locate,whereis,which
- 文件搜索命令 locate、find、whereis、which
- linux命令which whereis locate 命令
- linux学习(9)命令与文件的搜寻(which,whereis,locate,find)
- [JZOJ5335] 早苗
- 计算机系统概论
- 产品工程源代码调试之关注点1
- Linux用户组及用户的管理
- 多线程——worker-master模式
- 【Linux学习笔记】7:命令搜索命令whereis与which
- 百度瓦片地图制作
- IntentService和Service的区别
- 289. Game of Life
- canvas --画图、图片
- 百度地图定位
- 【CJOJ2440】大话西游(树链剖分)
- POJ-3186-Treats for the Cows-动态规划DP
- hdu6178Monkeys(bfs+输入挂模板)