Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4732787
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类:

2009-05-05 16:53:17

   一些相对简单点的 -type f -name什么的,就不说了。

1.为了在当前目录中文件属主具有读、写权限,并且文件所属组的用户和其他用户具有读权限的文件,可以用:
  find . -type f -perm 644 -exec ls -l {} \;

2.为了查找系统中所有文件长度为0的普通文件,并列出它们的完整路径,可以用:
  find / -type f -size 0 -exec ls -l {} \;

3.下面的find命令将删除当目录中访问时间在7日以来、含有数字后缀的admin.log文件。该命令只检查三位数字,所以相应文件的后缀不要超过999。
先建几个admin.log*的文件 ,才能使用下面这个命令
 find . -name "admin.log[0-9][0-9][0-9]" -atime -7  -exec rm {} \;
 
  注意当用到正则的时候,-name需要打引号,要不然就被shell给扩展了,导致有时候得不到正确的,或者其实是正确的而不是你想要的.

4.find +xargs
  find . -type f -print | xargs grep "hostname"

5.使用find查找文件的时候怎么避开某个文件目录

比如要在/usr/sam目录下查找不在dir1子目录之内的所有文件
find /usr/sam -path "/usr/sam/dir1" -prune -o -print
其实就是
if -path "/usr/sam"  then
          -prune
else
          -print

6.避开多个文件夹

find /usr/sam \( -path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -print

圆括号表示表达式的结合。
\ 表示引用,即指示 shell 不对后面的字符作特殊解释,而留给 find 命令去解释其意义。


查找某一确定文件,-name等选项加在-o 之后
find /usr/sam  \(-path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -name "temp" -print


7.查找某一时间段的文件
[root@mip-123456 shell]# touch -t 05040946 olderfile (5月4日9时46分)
[root@mip-123456 shell]# touch -t 05040950 newerfile (5月4日9时50分)

 
 find . -type f -newer olderfile -a ! -newer newerfile

这个我喜欢

阅读(1863) | 评论(0) | 转发(0) |
0

上一篇:firefox start in offline mode

下一篇:register变量

给主人留下些什么吧!~~