Guide to Chmod Permissions of Only Directories in Linux

The chmod command in Linux is a very valuable and often necessary function for fixing permissions of directories and their contents on a publicly accessible server.

When you are needing to change linx octet permissions for many folders and child folders and their contents, the -R recursive switch is of great value, as it saves you the trouble of having to switch directories and execute the chmod command time and time again.

Unfortunately, chmod is only able to execute commands on input parameters passed along to it specifying matches in the file name, and whether or not to chmod recursively or not. If your desire is to only chmod directories, but not the files, you have a problem.

To bypass the chmod command limitation, we will be utilizing stdin to stdout capability of the find and chmod commands.  Since find and chmod take advantage of  standard input / standard output capability, we are able to have them cross communicate sequentially in order to selectively pass along files to be chmod’ed which match our find query.

This command will  initiate a recursive search starting in the directory ” . ” (meaning current directory) locating all objects that are directories and execute the chmod command setting the permissions to 755.

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

This will recursively search your directory tree (starting at dir ‘dot’) and chmod 755 all directories only.

As needed, you may modify the command to suit your needs.

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

The permissions are the 3 digit numbers following the chmod command, and may be replaced with your desired Linux file system permissions in octet form (3 or 4 digits as needed).

To specify the current directory, replace the directory dot with

./



To specify a specific directory from the base mount point, you would type in the full path starting only with a slash, ie

/the/full/path/to/your/directory/

Now that you’ve changed the permissions of the directories, what are you going to do with all those files? Recursively chmod permissions of only files in linux.

Compartir:
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Slashdot
  • Technorati
  • Facebook
  • LinkedIn
  • Google Bookmarks
  • Current
  • Netvibes
  • Ping.fm
  • SphereIt
  • Sphinn
  • Tumblr
  • Live
  • Yahoo! Buzz

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply