What do {} and \ mean in 'sudo find /var/www/html -type d -exec chmod g+s {} \;'

971 views Asked by At

I'm running the command sudo find /var/www/html -type d -exec chmod g+s {} \; from here

It's said there that "We can set the setgid bit on every directory in our WordPress installation by typing the above command". The question is what do {} and / mean?

Running find --help gives Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec|time] [path...] [expression]...

So it seems like the above signs are somehow related to [path...] [expression], but their meaning is not clear.

2

There are 2 answers

0
Saqib Rokadia On BEST ANSWER

If you look at the man page for find you'll see that -exec will execute the command for every single result found. It will determine the end of the command by \;

It will also insert the name of the directory found at {}. So the command above says find every directory under /var/www/html and executes chmod g+s on it.

excerpt from man page:

-exec utility [argument ...] ;
         True if the program named utility returns a zero value as its exit status.  Optional arguments may be passed to the utility.  The expression must be terminated by a semicolon (``;'').  If you invoke
         find from a shell you may need to quote the semicolon if the shell would otherwise treat it as a control operator.  If the string ``{}'' appears anywhere in the utility name or the arguments it is
         replaced by the pathname of the current file.  Utility will be executed from the directory from which find was executed.  Utility and arguments are not subject to the further expansion of shell pat-
         terns and constructs.
5
Matthias Steinbauer On

{} is the placeholder for found files. And ; marks the end of the command executed by find's -exec option. The backslash escapes the semi-colon so that it's not interpreted by the shell as a metacharacter.