免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: fromeast
打印 上一主题 下一主题

[SOLARIS]用find命令时,怎样避免搜索下一级目录? [复制链接]

论坛徽章:
0
11 [报告]
发表于 2002-07-12 18:12 |只看该作者
$ ls
aa  bb  cc  dd
$ ls -l
total 4
drwxr-xr-x   2 ora   dba          512 Jul 12 18:05 aa
drwxr-xr-x   2 ora   dba          512 Jul 12 18:05 bb
-rw-r--r--   1 ora   dba            0 Jul 12 18:05 cc
-rw-r--r--   1 ora   dba            0 Jul 12 18:05 dd
$ ls
aa  bb  cc  dd
$ find . -name aa -prune -o -print;
.
./bb
./cc
./dd
$ $find . -name aa -prune -o -print -mtime +7 -exec rm -rf {} \\;
.
./bb
./cc
./dd
$ ls
aa  bb  cc  dd

论坛徽章:
0
12 [报告]
发表于 2002-07-12 20:39 |只看该作者
为什么不用过滤命令结合 起来呢?不能全依赖于find的阿

论坛徽章:
0
13 [报告]
发表于 2002-07-15 08:21 |只看该作者
in general, if you want to \"permanently save\" something, you\'d better put them somewhere else, if not on a diff fs, at least in a diff directory.  relying on tricks in a script not to remove something is tricky.  one day you might regret when you find out the script is not 100% bullet-proof.

having said that, try something like this:

cd <target directory>
/bin/rm -rf `find . |grep -v ^.\\/<sub directory>`

here is the idea.
find . will find everything under . and use grep -v to filter out those from the sub directory you want to save, and rm will remove them.

in find, add whatever criteria you want, e.g., mtime +7

论坛徽章:
0
14 [报告]
发表于 2002-07-15 09:13 |只看该作者

的确如你所说!为什么用-o就能屏蔽?

最初由 ahyan 发布
[B]$ ls
aa  bb  cc  dd
$ ls -l
total 4
drwxr-xr-x   2 ora   dba          512 Jul 12 18:05 aa
drwxr-xr-x   2 ora   dba          512 Jul 12 18:05 bb
-rw-r--r--   1 ora   dba            0 Jul 12 18:05 cc
-rw-r--r--   1 ora   dba            0 Jul 12 18:05 dd
$ ls
aa  bb  cc  dd
$ find . -name aa -prune -o -print;
.
./bb
./cc
./dd
$ $find . -name aa -prune -o -print -mtime +7 -exec rm -rf {} \\;
.
./bb
./cc
./dd
$ ls
aa  bb  cc  dd
[/B]

论坛徽章:
0
15 [报告]
发表于 2002-07-15 09:14 |只看该作者

没错,我太钻牛角尖了。

最初由 Fenng 发布
[B]为什么不用过滤命令结合 起来呢?不能全依赖于find的阿 [/B]

论坛徽章:
0
16 [报告]
发表于 2009-05-09 13:37 |只看该作者
请问楼主,这个问题最后怎么解决的?还记得吗?

论坛徽章:
0
17 [报告]
发表于 2009-08-23 19:50 |只看该作者
条条大路通罗马 一条不行  就去找别的路

论坛徽章:
0
18 [报告]
发表于 2009-09-28 16:52 |只看该作者
find . ! -name . -prune -type f -mtime +7 -exec rm {} \\;

论坛徽章:
0
19 [报告]
发表于 2009-09-28 21:23 |只看该作者
是这样的:
这个目录是存放自动备份文件的。我想做个自动执行的脚本,自动删除7天前的过期备份。但问题是这个目录下还有个子目录,是永久备份,不能删。find默认的情况是搜索到最后一层。
我看man find,说-xdev只搜索本目录,试了但不灵。

本文来自: IXPUB技术社区(www.ixpub.net) 详细出处参考:http://www.ixpub.net/thread-40881-1-1.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP