views:

70

answers:

2

I need to below permission policy to my files under www folder

664 to all files www recursively 755 to all directories under www recursively

I tried

find . -type f -exec chmod 644 {} ; 
find . -type d -exec chmod 755 {} ;

But always getting error

find: missing argument to `-exec'

What is the solution?

+3  A: 

Backslash before semi-colon (or quotes around it):

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;

The shell sees the semi-colon you typed as the end of the command and does not pass it to find, which then complains that it is missing.

Jonathan Leffler
An alternate that I use because I can never remember the -exec syntax is: <code>find . -type f | xargs chmod 0644</code>.
DanM
Me too, Dan. It also has the potential to execute fewer commands.
Jonathan Leffler
It is important to remember that the 'built-in' notation works correctly for file names with blanks and other odd characters in them. If you have paths with blanks in them and you are using `xargs`, use the `find` option `-print0` and the `xargs` option `-0`.
Jonathan Leffler
+1  A: 

Use backslash before ';'

find . -type f -exec chmod 644 {} \;
Staseg
Also you can find file and directoryes at the same timefind . -type f -or -type d
Staseg
But since the files need different permissions from the directories, the overall expression has to be rather complex then: `find . \( -type f -exec chmod 644 {} \; \) -o \( -type d -exec chmod 755 {} \; \)`. You might be able to avoid the parentheses; they are pretty much guaranteed to work, though.
Jonathan Leffler
You right. I'm inattentive.
Staseg