FIND and CHMOD Together

Getting directory and file permissions just right on Linux can be tricky because directories compared to files have different settings. This makes it so that a general, recursive chmod command will not work. This is where the power of using both 'find' and 'chmod' together comes in handy.

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


The above two commands do the following:

1. Search in the current directory represented by the dot.
find .

2. Look for the files or directories, respectively.
-type f
-type d

3. They execute the chmod command when they find it.
-exec chmod 644 {} \;
-exec chmod 755 {} \;

That's a really simplified example, but hopefully it helps out.

Tagged as , , , ,
Posted in Linux Command Line