Tips&Tricks

How to change permissions for file / directory recursively in Linux

Change owner for directory recursively:

sudo chown -R user:group /path/to/directory

Chown is a short for “change owner”, -R – means “recursively”, owner and group definition are separated by “:”. Also we need high privileges to run chown command – so we use “sudo”.

Change permissions only for directories recursively:

find /path/to/directory -type d -exec chmod 755 {} ;

Chmod is a short for “change mode”, “a+r” means “add read access for all”. Also we can use -R to set this mode recursively (makes sense for directories). But here we use number-notation: 755 means “readable & executable for all and writable for owner”.

Change permissions only for files recursively:

find /path/to/directory -type f -exec chmod 644 {} ;

For more information you can read an article about permissions in Linux / Unix.