which :命令查找
find: 文件查找,针对文件名
locate:文件查找,依赖数据库
which ls //从PATH环境变量
或者
whereis vim
语法:
find [path...] [options] [expression] [action]
命令 路径 选项 表达式 动作
按文件名:
find /etc -name "hosts"
find /etc -iname "hosts"
find /etc -iname "hos"
-i忽略大小写
结果输出:
/etc/hosts
文件查找成功
按文件大小:
find /etc -size +5M(大于5m)
find /etc -size 5M(等于5m)
find /etc -size -5M(小于5m)
指定查找的目录深度:
可查找范围
find / -maxdepth 4 -a -name "ifcfg-en"(在第四层找)
不可查找范围
find / -maxdepth 3 -a -name "ifcfg-en*"(在第三层找)
按文件属主、属组找:
按文件类型:
find /tmp -type f
find /dev -type b
f普通文件
b块设备文件
d目录
p管道
l连接
按文件权限:
find . -perm 644 -ls(-ls 是find的动作之一,精确权限)
找到后处理的动作 ACTIONS:
找到后默认是显示文件
find . -perm 715 -print(短格式)
find . -perm 715 -ls(长格式)
找到后删除
find /etc -name "775" -delete
找到后复制
find /etc -name "ifcfg" -ok cp -rvf {} /tmp \;
原文:https://blog.51cto.com/14881692/2516832