例子: find -name “CVS” -exec rm -rf {} \;

利用-name和-exec两个参数组合,可以实现批量查找删除指定文件的目的。

要活用find,它是很强大的。

find [path...] [expression]

-name pattern
Base of file name (the path with the leading directories removed) matches shell pattern pattern. The metacharacters (`*’, `?’, and `[]‘) do not match a `.’ at the start of the base name. To ignore a directory and the files under it, use -prune; see an example in the description of -path.
-exec command ;
Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of `;’ is encountered. The string `{}’ is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a `\’) or quoted to protect them from expansion by the shell. The command is executed in the starting directory.

http://hi.baidu.com/17ppc/blog/item/5b891700522034077bec2cee.html

Published in Linux
Tags: , , ,

No Responses to “linux下利用find进行批量删除CVS目录和文件的方法”

Leave a Reply

请输入算式结果(看不清请点击图片)
(必须)