you're reading...

How to set up UNIX permission for files and directories. Cleverly.

Sometimes you need to recursively set a specific UNIX permission for a whole set of files and/or directories. And you want to have a different permission for your files and for your directories.

For example, when installing a CMS like Joomla (or Moodle), you might want to recursively set the UNIX permissions to 700 for all the directories contained in your web root (say, your htdocs). And you want to do the same for all the files, but this time to 600.

This can easily be achieved by entering your htdocs and by using the find command:

find . -type d -exec chmod 700 {} +
find . -type f -exec chmod 600 {} +

The commands should be read as follows:

“Read everything in the current directory, recursively. For every single item that is of type directory (file) change permissions to 700 (600).”

The {} + option (refer to the find man page) runs the specified command on the selected files, but the command line is built by appending each selected file name at the end.

More information about UNIX permissions here.

About Roberto Aloi

Software Engineer and Erlanger. Author of www.tryerlang.org.


No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: