Unable to understand the syntax of the command fin

2020-02-26 07:07发布

The find command seems to differ from other Unix commands.

Why is there the empty curly brackets and a backward flash at the end of the following command?

find * -perm 777 -exec chmod 770 {} \;

I found one reason for the curly brackets but not for the backward flash.

The curly brackets are apparently for the path

Same as -exec, except that ``{}'' is replaced with as many pathnames as possible for each invocation of utility

标签: find
4条回答
beautiful°
2楼-- · 2020-02-26 07:50

The (escaped) semicolon is needed so that "find" can tell where the arguments to the exec'd program end (if there are any) and additional arguments to "find" begin.

查看更多
做自己的国王
3楼-- · 2020-02-26 07:55

I'd recommend that you instead do that as

find . -perm 777 -print0 | xargs -0 chmod 770

"xargs" says to take the results of the find and feed it 20 at a time to the following command.

查看更多
爷的心禁止访问
4楼-- · 2020-02-26 07:55

The string {} in find is replaced by the pathname of the current file.

The semicolon is used for terminating the shell command invoked by find utility.

It needs to be escaped, or quoted, so it won't be interpreted by the shell, because ; is one of the special characters used by shell (list operators).

See also: Why are the backslash and semicolon required with the find command's -exec option?

查看更多
Ridiculous、
5楼-- · 2020-02-26 08:03

The -exec command may be followed by any number of arguments that make up the command that is to be executed for each file found. There needs to be some way to identify the last argument. This is what \; does. Note that other things may follow after the -exec switch:

find euler/ -iname "*.c*" -exec echo {} \; -or -iname "*.py" -exec echo {} \;

(This finds all c-files and python files in the euler directory.)

The reason that exec does not require the full command to be inside quotes, is that this would require escaping a lot of quotes inside the command, in most circumstances.

查看更多
登录 后发表回答