Posts Tagged ‘Bash’

Changing file permissions recursively

November 26th, 2008

I often find myself wanting to both change the owner and file permissions of my web served files. When apache creates new files, the owner becomes www-data, and I can’t manipulate those files directly without changing the ownership to me. Also, apache can’t write to files if they aren’t writable by group. Well. The solution is very simple; I should fix my suPHP installtion. It worked some time ago but no longer. Anyway. The following three commands are a lifesaver.

sudo chown xxx:yyy -R .
find -type f -exec chmod 664 \{\} \;
find -type d -exec chmod 775 \{\} \;

The first one change ownership of files to user xxx group yyy recursively. The second one change permissions of all regular files (not directories) to whatever you want to (664 here). The third one change permissions of all directories. I want my directories to be executable, while I usually don’t want my files to be that. Find handles that for me.