linux文件名查找which,whereis,locate

1. 文件名查找


使用find查询时,由于磁盘查询,所以速度较慢,
所以linux下查询更常使用which, whereis, locate来查询,由于是利用数据库查询,所以速度很快。

2. which


我们常用的ls命令,如果我们想知道这些常用命令放在哪儿, 就使用which命令来查询地址。
which使用PATH 环境变量去查找文件名,
which -a 返回所有的查到的命令, 默认返回第一条。
$ which grep
/bin/grep

$ which ll
alias ll='ls -l --color=tty'
        /bin/ls
        #使用alias别名

3. whereis


whereis用来查询程序名
$ whereis
whereis [ -sbmu ] [ -SBM dir ... -f ] name...
-b : 查找二进制格式文件
-s : 查找source 源文件
-m : 查找在说明文件manual路径下的文件
-u : 查找不在上述三个选项中的特殊文件
例如
$ whereis grep
grep: /bin/grep /usr/share/man/man1/grep.1.gz /usr/share/man/man1p/grep.1p.gz

#查询二进制文件
$ whereis -b grep 
grep: /bin/grep

#查询手册说明文件 man grep 
$ whereis -m grep
grep: /usr/share/man/man1/grep.1.gz /usr/share/man/man1p/grep.1p.gz

3. locate


linux将系统内文件列在一个数据库文件(/var/lib/slocate/slocate.db)。
locate通过数据库文件查询。
一般这个文件每天更新一次, 配置在/etc/updatedb.conf
里面配置是否每天更新,以及更新目录。
可以手动运行
$ updatedb
来更新数据库。
使用locate,后面跟命令即可


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值