find 命令

用于文件查找

 ·find /path - 

参数

 -type 基于类型 
 
 f d s c b l 文件类型 
 find /etc -type f -name "ifc*"
 
 [root@localhost mnt]# find /etc -type f -name "ifc*"
 
 /etc/sysconfig/network-scripts/ifcfg-lo
 /etc/sysconfig/network-scripts/ifcfg-ens33
 
 
 
 -size 基于大小
  
 +5M 大于5M的文件
 5M 等于5M的文件
 -5M 小于5M的文件
 
 find /etc -type f -size +100K | xargs ls -hl 显示大于100k的文件
 
 
 -mtime 基于时间
 
 +7 7天以前
 7 第7天
 -7 最近7天
 
 
 find /etc -type f -name "file-*" -mtime +7 |xargs rm -f 
 保留最近7天的文件,删除7天以前的文件
 
 -user  基于用户
 -group 基于组
  
  find /home -user jack
  在目录下找到属主jack的文件
  
  find /home -group jack
  在目录下找到属组的文件
  
  -nouser -nogroup
  查找没有属主或则属组的文件
  
  -a 并且  -o 或者
  
  # -nouser -a -nogroup 
  
  
  -delete 删除
  -ok 后面跟自定义shell命令(会提示是否操作)
  
  -exec 逐个执行但不会提示
  find -type f -name "file*" -exec cp -rv {} /tmp \;
  同
  find -type f -name "file*" | xargs cp -rvf /tmp/
  
  -exec后面跟着shell命令
  cp -rv {} /tmp 
  {}就是find找到的东西,就是参数
  /tmp 复制到的地方 
  
 \;是固定搭配
  
 ! 取反
 
 -wireable -readable -executeable 权限条件
 
 -perm 755或者/+r /+w 都可以
 
 -path 后面加上路径,只找这路径里面的文件
 find /etc/ -path /etc/sane.d -prune -o -name "*.conf"
 在/etc/下找*.conf的文件,排除/etc/sane.d里面的
 -prune 跳过目录

### 过滤

 ·find ./ -type f |xargs grep "XX"
 从文件中找到写有XX的文件
 
 | awk '/tree|aaaa/'
 | sed -rn '/tree|aaa/'
 
 awk -v IGNORECASE=1 '/XXX/' 路径 在路径中查找xxx的行,忽略大小写 -v是改参数
 
 
 

xfxfxf
11 声望1 粉丝