Skip to main content

Use the chmod command to change the access permissions of a file or directory.

# To give the [u]ser who owns a file the right to e[x]ecute it:
chmod u+x <file>

# To give the [u]ser rights to [r]ead and [w]rite to a file/directory:
chmod u+rw <file_or_directory>

# To remove e[x]ecutable rights from the [g]roup:
chmod g-x <file>

# To give [a]ll users rights to [r]ead and e[x]ecute:
chmod a+rx <file>

# To give [o]thers (not in the file owner's group) the same rights as the [g]roup:
chmod o=g <file>

# To remove all rights from [o]thers:
chmod o= <file>

# To change permissions recursively giving [g]roup and [o]thers the ability to [w]rite:
chmod -R g+w,o+w <directory>

# ---

# Makes the permissions of file2 the same as file1 (GNU version only):
chmod --reference <file1> <file2>

# change pemissions (chmod) of all `css` and `js` files to 644:
find . -type f -iname "*.css" -or -iname " *.js" -exec chmod 644 {} \;
# NOTE: to preview changes first, remove the `-exec chmod 644 {} \;` part
find . -type f -iname "*.css" -or -iname " *.js" -exec echo {} \;

# Change all directories on your filesystem to a permissions level of 755:
find . -type d -exec chmod 755 {} \;

# This one looks for dynamic files (e.g., PHP scripts); it changes the ones
# it finds to a permissions level of 700.
find . -type f -iname "*.php*" -or -iname "*.cgi" -or -iname "*.pl" -or -iname "*.py" -or -iname "*.rb" -exec chmod 700 {} \;

# Change all apache config files to 644:
find /usr/local/etc/apache22 -type f -iname "*.conf" -exec chmod 644 {} \;