linux系统find命令使用
文章目录1.find命令2.参数3.案例3.1按条件查找文件3.2对fing找出来的结果二次处理1.find命令按条件查找文件『-a交集 -o并集』 默认交集 递归查找指定目录下面一层层找2.参数-type f文件 d目录 l快捷方式 b块设备文件 c字符设备文件-name ‘文档名称’ -iname 不分大小写-size /-文件大小k、M、Gbug1G改1024M-iname 不分大小写-maxdepth 限制目录查找的最大深度如2 指定目录及它下一级子目录查找加起来查找2层目录-mtime 2第二天24-48小时 -2两天前48小时内 2超过2天以前修改的文件-user username 所属用户-group groupname 所属组-print 打印查找出来的文件默认不需配但在对查找出来二次处理前可用到3.案例3.1按条件查找文件查找当前目录下面名字后缀.exe结尾的文件find . -name ‘*.exe’ -type f -print -exec rm -rf {} ;根目录下面找用户student的所有文件find / -user student -type f找出显示大于2M文件find /var/ -size 2M查找第3层uos文件find /home/ -maxdepth 3 -mindepth 3 -name uos超过30天以前find /var/log -mtime 30在/test下面找文件除了/test/test3下面不去找find /test -path “test/test3” -prune -o printcat /etc/passwd3.2对fing找出来的结果二次处理find结果处理 -exec [command] {} 路径 ;-print表示二次处理前先打印出来find查找到的结果复制-exec cp {} path ;删除-exec rm -rf {} -print ;把查找结果强制复制到指定目录 \cp –p $(find / -user student –type f ) /root/qiang/把查找出来内容进行复制到指定目录find / -user student -type f -exec cp {} /root/qiang/ ;把查找出来的文件二次过滤后执行删除find -type d | grep .svn$ | xargs rm -r统计找出来的文件find /root -name ‘nsd*’ -a -type d | wc -l导入输出结果到文件(正确信息)find / -name xxx /tmp/tmpfile导入输出结果到文件(错误信息)find / -name xxx 2/tmp/tmpfile导入输出结果到文件(错误信息)find / -name xxx 2/tmp/tmpfile