find命令基本使用一览,find命令使用一览


find命令相对于locate这种非实时查找的搜索命令,大大增加了我们搜索的便捷度以及准确性;并且能够方便的帮助我们对大文件、特定类型的文件查找与删除,特别是有超多小碎文件的时候,更是方便至极.... 根据属主 属组查找
   -user username:查找属主是xx的文件
   -group group:查找属组的xx文件
   -uid useruid:查找uid号的文件
   -gid groupid:查找gid号的文件
   -nouser:查找没有属主的文件,即文件存在但是 user已被删除
   -nogroup:查找没有属组的文件
根据文件类型查找
    -type f:普通文件
   -type d:目录文件
   -type l:符号链接文件
   -type s:套接字文件
   -type b:块设备文件
   -type c:字符设备文件
   -type p:管道文件
根据大小查找
    -size +10M :大于10m的文件
    -size +10k:大于10k的文件
    -size +1G:大于1G的文件
    -size -1G:小于文件的文件
根据时间查找
    一天为单位
        -atime :访问时间
        -mtime :修改时间
        -ctime :改变时间
   以分钟为单位:
        -amin: 访问时间
-mmin:修改时间
-cmin:改变时间
根据权限查找
    -perm +mode:
    -perm +600:属主属组其他权限 只要有一个匹配就当成功;600代表三个对象,6属主 CentOS7上 使用 /600
    -perm -600:每个对象都必须同时拥有其指定的权限,三个对象同时成立 如:-003表示其他用户必须有写与执行权限
组合条件查找
   -a  :与
   -o  :或
   -not:非
   !  :非
处理动作
    -print:打印到屏幕
    -ls:查找到的文件 进行 ls
    -delete:删除查找到的文件
    -ok command {}\; 对查找的文件执行由command指定的命令,交互式
    -exec command {}\;同上,非交互式
    {}:代表前面find找到的 文件名称本身
    例如:
    find ./ -type f -exec cp {} {}.bak \; 将查找到的文件都复制出一个.bak文件
find查找后的动作传递模式 默认:查找到指定类型的文件时进行一次性传递 xargs:xargs命令即让find查找的传递模式为 查找一个传递一个到动作上,删除较多碎文件很好用,例如:find -type f | xargs command;相关示例介绍:
查找/home/test目录下的符号*.txt的文件
find /home/test -name "*.txt" -print
查找权限是755的
find /home/test -perm 755 -print
查找属主是test的
find /home/test -user test -print
查找数组是test的
find /home/test -group test -print
查找更改时间小于5天的
find /home/test -mtime -5 -print
查找更改时间大于3天的
find /home/test -mtime +3 -print
查找所有目录
find /home/test -type d -print
查找除了目录的所有文件
find /home/test ! -type d -print
查找文件
find /home/test -type f -print
查找符号链接文件
find /home/test -type l -pint
不包括/home/test/test/目录下的test.sh
find /home/test -name "test.sh" -prune /home/test/test -print
删除test.sh文件
find /home/test -name "test.sh" -type f -exec rm {} \;
显示以test开头的文件
find /home/test -name "*test*" -type f -exec more {} \;

 

 

相关内容

    暂无相关文章