一、locate命令查找文件

locate命令是在后台数据库中按文件名查找,查找速度快,非实时的。

1、安装mlocate

yum -y install mlocate

2、更新数据库

updatedb

3、查找文件

locate ifcfg-eth0

二、whereis和which

1、whereis

whereis查找命令路径和帮助文件

whereis -b cmd // 返回命令路径

whereis -m cmd // 返回帮助文件路径

2、which

which cmd 返回命令路径

三、Find查找文件

1、find命令基本语法

find 路径 选项 表达式 动作

根据文件大小查找 // 查找/etc目录下文件大小大于5M的文件 find /etc/ -size +5M

根据文件类型查找 //查找/dev目录下块设备文件 find /dev -type b

根据时间查找 //查找用户家目录下7天前的文件

根据用户查找 // 查找centos家目录下文件 find /home/centos -user centos

根据权限查找 // 查找755权限文件 find ./shell_scripts/ -perm 755 -ls

2、find 处理动作

-print :打印查找到的内容(默认) -ls:以长格式显示的方式打印查找到的内容 -delete:删除查找到的文件(仅能删除空目录) -ok:后面跟自定义Shell命令(会提示是否操作) -exec:后面跟自定义Shell命令(标准写法 -exec ;)