Linux系统文件查找详解

今天给伙伴们分享一下Linux文件查找详解,希望看了有所收获。

我是公众号「想吃西红柿」「云原生运维实战派」作者,对云原生运维感兴趣,也保持时刻学习,后续会分享工作中用到的运维技术,在运维的路上得到支持和共同进步!

如果伙伴们看了文档觉得有用,欢迎大家关注我的公众号,获取相关文档。爱运维,爱生活。

一、which

  • shows the full path of (shell) commands.

  • 显示(系统)命令所在目录

[root@edenluo.com ~]# which ls
alias ls='ls --color=auto'
	/bin/ls
[root@edenluo.com ~]# which ll
alias ll='ls -l --color=auto'
	/bin/ls
[root@edenluo.com ~]# which sshd
/usr/sbin/sshd
[root@edenluo.com ~]# which mysqld
/usr/sbin/mysqld
[root@edenluo.com ~]# which mysql
/usr/bin/mysql

二、whereis

  • locate the binary, source, and manual page files for a command

  • 除了可查看此命令所在的路径,还可以查看此文件相关的帮助文档所在路径,命令原始路径,命令配置文件(如果有) 帮助文件(如果有)

[root@edenluo.com ~]# whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz
[root@edenluo.com ~]# whereis sshd
sshd: /usr/sbin/sshd /usr/share/man/man8/sshd.8
[root@edenluo.com ~]# whereis mysqld
mysqld: /usr/sbin/mysqld /usr/share/man/man8/mysqld.8.gz
[root@edenluo.com ~]# whereis which
which: /usr/bin/which /usr/share/man/man1/which.1.gz

三、whatis

  • 解释命令的意义/功能;获得此命令的索引的简短说明信息

  • 备注:许多Linux系统中并未默认安装此软件,需手动下载、安装。

  • 可等效于man <command> / <command> --help

[root@edenluo.com ~]# whatis cp 
cp (1)               - 复制文件和目录
cp (1p)              - copy files
[root@edenluo.com ~]# whatis service 
service (8)          - run a System V init script
[root@edenluo.com ~]# whatis systemctl 
systemctl (1)        - Control the systemd system and service manager

出错显示:

[root@edenluo.com ~]# whatis cp 
cp:没有 appropriate。

原因:

  • whatis是根据数据库执行查找操作的
  • 数据库是定是跟新的,但新安装的系统还未自动跟新

方法:

  • root权限下
  • 使用makewhatis手动更新(OS7版本以下)
  • 使用mandb进行更新(OS7及其以上)

四、locate

  • locate 指令和 find 找寻档案的功能类似,但 locate 是透过 update 程序将硬盘中的所有文件和目录资料先建立一个索引数据库,在执行 loacte 时直接找该索引,查询速度会较快,索引数据库一般是由操作系统管理,但也可以直接下达update强迫系统立即修改索引数据库。
locate:依赖于事先构建好的索引库
	1、系统自动实现(周期性任务)
	2、手动更新数据库(updatedb)

locate 工作特性:
	1、查找速度快
	2、模糊查找
	3、非实时查找
1、locate 命令格式
locate  [OPTION]...  PATTERN...
	-b:只匹配路径中的基名
	-c:统计出共有多少个符合条件的文件
	-r:BRE,使用正规运算式 做寻找的条件
[root@edenluo.com ~]# locate 被查找的关键字
注意:索引构建过程需要遍历整个根文件系统,极消耗资源。
2、命令示例
示例:
[root@edenluo.com ~]# locate /etc/sh       # 查找 /etc 下以 sh 开头的文件
/etc/shadow
/etc/shadow-
/etc/shells
[</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

尘嫣慕曦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值