which
本文测试所用环境为centos8
which用来从PATH内寻找命令路径,如:
$ which cd
/usr/bin/cd
$ which vim
/usr/bin/vim
whereis
whereis 用来搜索指定名称的二进制文件,源码,和说明文件。
常用参数如下:
-b 只找binary格式的文件
-m 只找在说明文件manual路径下的文件
-s 只找source来源档案
-u 搜寻不在上述三个项目中的其它特殊档案
帮助页里看不懂的话…大家都说从数据里找,这里好像说从标准的linux地方还有path里找?英语太差了,我也不知道
whereis then attempts to locate the desired
program in the standard Linux places, and in the places specified by $PATH
and $MANPATH.
$PATH的值可通过
echo $PATH
查看,区分大小写。
locate
locate是从数据库中搜索,使用该命令时,如果出现
“locate: can not stat () ‘/var/lib/mlocate/mlocate.db’: No such file or directory”则需要执行updatedb
来建立数据库。如果要搜索新建的文件,也需要执行updatedb
来更新数据库。(手册里说,updatedb
通常通过cron
每天执行一次。所以,如有需要,也可以自行修改相应的配置。)。
locate的使用格式为 locate [OPTION]... PATTERN...
, 这里为pattern,可以使用通配符,如果不指定通配符,则默认前后都加,如,locate hello
就等于locate *hello*
。若指定,则按指定的匹配。而且locate的匹配有wholename
(路径和文件名)和basename
(只包含文件名)两种模式,且默认为wholename
,也就是说,如果搜索locate python*
将什么也找不到,可以使用-b
指定按basename搜索。
常用的参数有:
-A # 需匹配全部pattern
-b # 按base name匹配
-c # 只输出个数
-i # 忽略大小写
-r # 使用基本的正则表达式匹配
--regex # 使用扩展的正则表达式
如:
[light@localhost ~]$ locate -A yum .g # 同时满足*yum* 和*.g*
/usr/share/man/man1/yum-aliases.1.gz
/usr/share/man/man1/yum-changelog.1.gz
/usr/share/man/man5/yum-changelog.conf.5.gz
/usr/share/man/man5/yum.conf.5.gz
/usr/share/man/man8/yum-rhn-plugin.8.gz
/usr/share/man/man8/yum-shell.8.gz
/usr/share/man/man8/yum.8.gz
/usr/share/man/man8/yum2dnf.8.gz
find
命令格式:
find [PATH] [option] [action]
find是从硬盘中查找,所以速度相对whereis和locate较慢。
以下内容摘自鸟哥的Linux私房菜。
1. 与时间有关的选项
-atime, -ctime, -mtime其中atime指最后取时间,ctime指状态最后修改时间,mtime指内容最后修改时间:
以mtime为例:
-mtime n n为数字,意为在n天之前的一天内被更改过内容的文件
-mtime +n 列出在n天之前不含(不含n)被改动过内容的文件
-mtime -n 列出在n天之内被改动过内容的文件
如果n为0代表当前时间,为从现在开始到24小时前
-newrer file file为一个存在的文件,列出file还要新的文件
如:
find /var -mtime -4 # 列出4天内内容改动过的文件
用一幅图来描述就是:
2. 与使用者或组名有关的参数
-uid n # n为用户的账号ID
-gid n # n为组名的ID
-user name # name为账号名称
-group name # name为组名
-nouser # 寻找档案的拥有者不存在于/etc/passwd的文件或目录 一般是从网络中下载的文件,或已删除用户遗留文件
-nogroup # 寻找文件的拥有者不存在于/etc/group的的文件或目录 如:find / -nogroup
3. 与档案权限及名称有关的参数
-name filename
-size [+-]SIZE # SIZE规格有c(byte), k(1024byte)如:find / -size +50k 找比50KB大的档案
-type TYPE # f, b, c, d, l, s, p
-perm mode # 搜索权限刚好等于mode的
-perm -mode # 搜索权限全部囊括mode的
-perm +mode # 搜索权限包含任一mode的
如:
find / -perm 4700 # 搜索权限等于rws------的
4. 额外可进行的动作
-exec command
如:
find / -nogroup -exec ls -l {} \;
这里{}为前面find / -nogroup
产生的结果,command不支持命令别名,如ll
。
参考:
https://www.cnblogs.com/JMLiu/p/7643385.html