150 views
首页 > 工作 > find命令中的-exec选项与shell里的exec命令

find命令中的-exec选项与shell里的exec命令

find ./ -name “.*log” -exec sed -i ‘s/localhost/127.0.0.1/’ {} \;

查找当年目录下的所有log文件,找到一个就执行一次-exec后面的命令,把找到的内容放入{}中进行替换。

“-exec”作为find命令的一个option, 其功能是

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.

与Shell里的exec命令是不一样的

exec [arg]
If arg is present, executes arg in place of this shell.

anyShare分享到:
分类: 工作 标签: ,
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.