1.简介
which :命令查找
find: 文件查找,针对文件名
locate:文件查找,依赖数据库
一、命令文件查找
1.查找ls 命令的位置
which ls //从PATH环境变量或者whereis vim
二、任意文件
locate
1.locate查找文件hosts文件
[root@localhost ~]# locate hosts
2.更新locate数据库
[root@localhost ~]# updatedb
一.find 查找
语法
find [path…] [options] [expression] [action]
命令 路径 选项 表达式 动作
1.按文件名:
[root@localhost ~]# find /etc -name “hosts”
[root@localhost ~]# find /etc -iname “hosts”
[root@localhost ~]# find /etc -iname “hos*”
-i忽略大小写
2.按文件大小查找:
[root@localhost ~]# find /etc -size +5M
[root@localhost ~]# find /etc -size 5M
[root@localhost ~]# find /etc -size -5M
文件>5M
文件=5M
文件<5M
3.指定查找的目录深度:
可查找范围
[root@localhost ~]# find / -maxdepth 4 -a -name “ifcfg-en*”
查询是成功的
不可查找范围
[root@localhost ~]# find / -maxdepth 3 -a -name “ifcfg-en*”
查询是失败的
4.按文件属主、属组找:
[root@localhost ~]# find /home -user jack //属主是jack的文件
[root@localhost ~]# find /home -group hr //属组是hr组的文件
5.按文件类型:
[root@localhost ~]# find /tmp -type f
[root@localhost ~]# find /dev -type b
f普通文件
b块设备文件
d目录
p管道
l连接
6.按文件权限:
[root@localhost ~]# find . -perm 644 -ls
-ls 是find的动作之一,精确权限
找到后处理的动作 ACTIONS:
7.找到后默认是显示文件
[root@localhost ~]# find . -perm 715 -print
-print显示文件名
[root@localhost ~]# find . -perm 715 -ls
-ls显示文件属性
找到后删除
[root@localhost ~]# find /etc -perm “775*” -delete
找到后复制
[root@localhost ~]# find /etc -name “ifcfg*” -ok cp -rvf {} /tmp \;