码迷,mamicode.com
首页 > 其他好文 > 详细

Find 常用命令的使用 (下)

时间:2016-05-09 20:44:27      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:find   perm   

四、根据权限来查找  

 -perm  


 root@localhost:~# find /boot/ -perm 755

/boot/

/boot/grub

/boot/grub/locale

 

 

五、按查找的目录深度

 

-maxdepth  查找目录的深度   

 

-maxdepth  1  只查找目录第一层的文件和目录  

 

-maxdepth  2  只查找目录1层和第二层的文件和目录  

 

举例说明  

 

root@localhost:~# find /boot/ -maxdepth 1  

/boot/

/boot/memtest86+.bin

/boot/config-3.2.0-67-generic

/boot/initrd.img-3.2.0-67-generic

/boot/vmlinuz-3.2.0-67-generic

 

root@localhost:~# find /boot/ -maxdepth 2 | head -6

/boot/

/boot/memtest86+.bin

/boot/config-3.2.0-67-generic

/boot/initrd.img-3.2.0-67-generic

/boot/vmlinuz-3.2.0-67-generic

/boot/System.map-3.2.0-67-generic

 

 七、多条件结合

 

-a  -o  !  即  -and   -or    -not  

 

举例说明

 

root@localhost:/usr/local/src/test# find /usr/local/src/test/  -type f  -and -perm -644 | head -3

/usr/local/src/test/1.html

/usr/local/src/test/5.html

/usr/local/src/test/8.html

 

动作

 

-print  

 

-exec  需要执行的命令

 

rm 要执行的命令

 

{}  表示 find  -type f  查出来的文件内容

 

\; {} \; 之间要有空格。

 

举例说明  

 

查当前目录下的所有普通文件

 

 find . -type f -exec ls -l {} \;   

root@localhost:/usr/local/src/test# find /usr/local/src/test/ -type f -exec ls -l {} \;

/ l o g s目录中查找更改时间在5日以前的文件并删除它们:
 find logs -type f -mtime +5 -exec   rm {} \;

 

查找当前目录下面创建的文件并删除  

find /usr/local/src/test/ -type f -mtime -1 -exec  rm -f  {} \;  

 

find /usr/local/src/test/ -type f -mtime -1 | xargs  rm -f  

 

查询当天修改过的文件
find /home/  -mtime -1 -type f  -exec ls -l {} \;  

比如要查找磁盘中大于70M的文件:

 

find  / +size +70M -exec ls -l {} \;


本文出自 “10852974” 博客,请务必保留此出处http://10862974.blog.51cto.com/10852974/1771563

Find 常用命令的使用 (下)

标签:find   perm   

原文地址:http://10862974.blog.51cto.com/10852974/1771563

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!