2

I am trying to figure out what the following command would do. I extracted it from a Linux shell script and when I enter it goes to a prompt (>). But I cannot figure out what to enter in this prompt.

    find ~/dev/tools/flex-4.5.0.20967 -type d -exec chmod o+rx '{}' \

I know the purpose of the find command here. It is searching for the specified directory, checking whether it is indeed a directory and executing the chmod command on that directory. What I cannot figure out is the format of the chmod command here.

I checked man page of chmod but cannot determine the functionality of the above chmod format.

Thanks.

4

4 に答える 4

5

Check the man page for find. the {} \; is specific to the -exec flag for find

The > prompt appeared because you missed a ';' at the end of '\;'

find ~/dev/tools/flex-4.5.0.20967 -type d -exec chmod o+rx '{}' \;

The command finds all sub-directories under ~/dev/tools/flex-4.5.0.20967. without the -type d it will also include files under the folder.

The -exec my_command my_args1 my_args2 '{}' \; part specifies for each matched result by find , execute the command my_command as :

my_command my_args1 my_args2 matched_result

The {} is replaced with the matched result , in this case a directory, the \; is to indicate the termination of arguments for my_command

于 2012-10-11T09:03:35.403 に答える
4

chmod : "Change Mode", usually used to set or change file permissions.

o+ Add permission for "others" (other possible values are u(user) and g(group) with - (remove)

r Read permission

x Execute permission (other possible values include w - write permission)

{} is the device used by find to indicate "insert the current filename here" in the command being executed.

于 2012-10-11T09:03:57.717 に答える
1

The man page to be checked is of the find command. chmod works on every directory which is resulting from the find command. So, to tell where in the chmod command the directory is to be placed, it is indicated using '{}' syntax.

For example, to move every .txt file resulting from the find command to a ~/backup dir:

find . -name "*.txt" -exec mv '{}' ~/backup \;

Hope this helps.

于 2012-10-11T09:10:18.973 に答える
0

The find command searches for all sub-directories in ~/dev/tools/flex-4.5.0.20967. For every found directory it executes chmod o+rx '{}' on it. The '{}' sign is replaced with a currently found sub-directory name.

于 2012-10-11T09:04:49.167 に答える