Apache / Linux · January 14, 2016 0

Linux: Add permission only on directory or files

That’s why I love linux, it has great deep level control over system, you can set permissions on just directories and skip files or just on files and skip directories. Isn’t that wonderful?

In a web environment you don’t want to make core files writable but you want to have permissions for execute and read, and still you need directories writable to accept new files. That is fairly easy to do in linux.

Changing file permissions to not writable but executable and readable

find files using “-type f” and execute a command of chmod with permissions.

find . -type f -exec chmod 0555 {} \;

Changing directory permissions to writable only by owner but executable and readable

find directories using “-type d” and execute a command of chmod with permissions.

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

That’s it.