Hello World

Linux : find

1. 简介

在指定目录下查找指定条件的文件

2. 用法

  -user: 指定文件拥有者名称
  -uid: 指定uid
  -group: 指定用户组
  -gid: 指定gid

  -name: 指定文件名的格式,*.txt : 以 txt 结尾的文件,aa*,以aa开头的文件名
  -size : 指定大小的文件,+100M:大于100M,100M:等于100M,-100M:小于100M
  -type: 指定文件类型,b:块设备,c:字符设备,d:目录,f:普通文件,l:符号链接,s:套接字文件,p:Fifo

  -mindepth: 指定最小目录深度
  -maxdepth: 指定最大目录深度

  -false: 设置回传值为false
  -true: 设置回传值为true
  -exec: 回传值为true时执行指定的指令,find  /  "*.tar.gz"  -exec ls {}  \;
  -ok: 效果同 exec,但是在执行执行时会询问用户

  -xdev: 指定文件系统
  -mount: 指定文件系统

3. 示例

查找大于1G的文件并排序

      find   /   -type  f   -size +1G  -print0  | xargs -0 du  -h  | sort -n

查找大于1G的文件并排序,忽略/proc目录

      find  /  -path "/proc" -prune -o -type  f   -size +1G  -print0  | xargs -0 du  -h  | sort -n

忽略多个目录

      find  /  \( -path "/proc" -o -path "/storage" -o -path "/data/" \) -prune -o -type  f   -size +100M  -print0  | xargs -0 du  -h  | sort -n

在目录下查询指定文件并执行命令

     find /data -name "xxx.txt" -exec ls -l {} \;
posted @ 2020-09-07 19:58  小小忧愁米粒大  阅读(194)  评论(0编辑  收藏  举报
瞅啥瞅,好好看书