Wednesday, 13 June 2007

find -exec


-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.



-exec 参数后面跟的是 command命令,注意点如下:

command命令的终止,使用 ';' (分号)来判定,在后面必须有一个 ';'


特别强调,对于不同的系统,直接使用分号可能会有不同的意义, 使用转义符 '\'在分号前明确说明,对于前面我们遇到的问题,主要就是这个原因引起的!



find / -exec grep "Hello" {} \;


find / -name "*.tmp" -exec rm -f {} \;

No comments:

My photo
London, United Kingdom

Facebook & Twitter