|
|
第 1 帖 | |
|
|
标题: 这个脚本怎么写? 我想删除掉/tmp下的所有大于1m的文件,并让他定时执行,怎么写啊?
还有我想删除/http下所有的超过两周没有更新的文件,应该怎么写啊? 谢谢高手帮忙!
__________________
日本人和狗禁止浏览!! 虽然我的电脑被我卖了,但她将永远活在我的心中~~~~ my msn:babyish0@hotmail.com 欢迎大家来我的论坛,刚刚开张的: http://linuxqa.go.3322.org |
|
|
|
|
|
|
|
第 2 帖 | |
|
|
1,可以用for:
代码:
可以先用echo $file来测试,以免发生~~~~ ![]() 2,可以用find: 代码:
此帖于 03-11-18 19:46 被 KornLee 编辑. |
|
|
|
|
|
|
|
第 3 帖 | |
|
|
javalee 老大,
您看这第一个问题这样好吗? 1. find /tmp -size +1000k -type f -exec rm -rf {} \; 第二题我感觉用ctime 更合适,不知对否。 |
|
|
|
|
|
|
|
第 4 帖 | ||
|
|
引用:
可以找出任何适合自己的,自己喜欢的解题方法~~,![]() 实践出真知嘛~~ BTW:我可不是老大 :o (我现在是族长啦 ),同时谢谢werix兄的指点 |
||
|
|
|
||
|
|
第 5 帖 | |
|
|
代码:
|
|
|
|
|
|
|
|
第 6 帖 | |
|
|
hmm,
[root@linux1 tmp]# dd if=/dev/zero of=test2.img bs=1M count=2 2+0 records in 2+0 records out [root@linux1 tmp]# dd if=/dev/zero of=test.img bs=1M count=2 2+0 records in 2+0 records out [root@linux1 tmp]# time find /tmp -size +1000k -type f -print0 | xargs -r0 rm -- real 0m0.030s user 0m0.002s sys 0m0.014s [root@linux1 tmp]# dd if=/dev/zero of=test2.img bs=1M count=2 2+0 records in 2+0 records out [root@linux1 tmp]# dd if=/dev/zero of=test.img bs=1M count=2 2+0 records in 2+0 records out [root@linux1 tmp]# time find . -size +1000k -type f -exec rm -rf {} \; real 0m0.011s user 0m0.004s sys 0m0.006s 到底谁快呢?多次结果都不一样.不过多谢了,又学了一招 |
|
|
|
|
|
|
|
第 7 帖 | |
|
|
多谢r2007兄和werix兄的指点~~,
![]() |
|
|
|
|
|
|
|
第 8 帖 | |
|
|
猜想find是并发调用-exec中的命令,数量少时不会很慢。
理论上讲,文件数量多时用xargs性能会有明显改善。 纸上谈兵,希望能抛砖引玉。 |
|
|
|
|
|
|
|
第 9 帖 | |
|
|
-exec是对每一个文件一次一个的操作,同样要求为每个操作生成一个进程,而xargs像r2007兄所说的,是很高效的,我们可以根据文件数量的多少作出选择!
![]() |
|
|
|
|
|
|
|
第 10 帖 | |
|
|
对,我也觉得文件少了点。。。兄弟能不能给解释一下为什么 -r0必须放在rm 之前? 我去掉它命令就只删一个文件了。。。不明白,还望阐明原理,谢过了。
|
|
|
|
|
|
|
|
第 11 帖 | |
|
|
ok, I start to understand... with man xargs ...
xargs exits with the following status: 0 if it succeeds 123 if any invocation of the command exited with status 1-125 124 if the command exited with status 255 125 if the command is killed by a signal 126 if the command cannot be run 127 if the command is not found 1 if some other error occurred. --no-run-if-empty, -r If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there is no input. |
|
|
|
|
|
|
|
第 12 帖 | |
|
|
在rm命令行参数中末尾加上--然后再加文件名,可以确保删除掉以-打头的文件,平时在提示符下运行时,文件名是已知的,不会存在太大问题。在脚本中一般并不能预先知道将要操作的文件名,所以--参数是有必要的。如:
rm -rf -- -file1 ---file2 #删除文件-file1和---file2 也许大家主要为了阐述解决问题的思路,不必要太在意细节。但是为了对楼主和各位负责,还有自己的一点点较真的毛病,还是在这儿罗嗦两句。 |
|
|
|
|
|
|
|
第 13 帖 | ||
|
|
引用:
|
||
|
|
|
||
|
|
第 14 帖 | |
|
|
谢谢个位帮忙,使我大有收获!呵呵
|
|
|
|
|
|