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

user1920187 picture user1920187 · Nov 2, 2013 · Viewed 109.3k times · Source

why doesn't this work I am trying to change all files to 644 abd all -d to 755:

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

i get: find: missing argument to `-exec' thanks

Answer

Phil picture Phil · Feb 28, 2014

Piping to xargs is a dirty way of doing that which can be done inside of find.

find . -type d -exec chmod 0755 {} \;
find . -type f -exec chmod 0644 {} \;

You can be even more controlling with other options, such as:

find . -type d -user harry -exec chown daisy {} \;

You can do some very cool things with find and you can do some very dangerous things too. Have a look at "man find", it's long but is worth a quick read. And, as always remember:

  • If you are root it will succeed.
  • If you are in root (/) you are going to have a bad day.
  • Using /path/to/directory can make things a lot safer as you are clearly defining where you want find to run.