How-To: Changing File/Folder permissions under Linux

Often files located in “touchy” spots are inaccessible by certain programs and users, and rightfully so.  But for those of us who need access to such files, or think we do (hehe), the command “chmod” is your friend.  You will have to run this command under root privledges.  First, let’s look over the binary version of this affair:

Read on for more!

Symbolic Notation Octal Notation English
———- 0000 no permissions
—x–x–x 0111 execute
–w–w–w- 0222 write
–wx-wx-wx 0333 write & execute
-r–r–r– 0444 read
-r-xr-xr-x 0555 read & execute
-rw-rw-rw- 0666 read & write
-rwxrwxrwx 0777 read, write, & execute

I prefer to write out chmod commands, but some prefer the “symbolic” way of doing this, technically referred to as “octal notation,” which I will get to later on.  Each line on the far left represents a “group,” each in sets of 3 ( — , —, —-), prefixed at the beginning with the bit that determines if its a directory or not (we don’t modify that party anyway typically).  chmod includes these three options when you are running the command:

  • -R recursive, i.e. include objects in subdirectories
  • -f force, forge ahead with all objects even if errors occur
  • -v verbose, show objects processed

Octal Notation:

  • Refer to the chart above.  There is an explanation behind this, so keep reading if you wish to have it explained or skip to “Symbolic Modes” below.
  • Still here? Great!  Octal notation accepts these inputs:
# Permission rwx
7 full 111
6 read and write 110
5 read and execute 101
4 read only 100
3 write and execute 011
2 write only 010
1 execute only 001
0 none 000
  • How this works out is we go back to our groups, —,—,—.
  • The rightmost three groups are for the file owner, the group and other users, in order.
  • Remember earlier that 0 at the very* begining of somthing such as “chmod 0755?”  Here is what that means:

 6-20-2013 15-07-34

  • Each bit represent a power of 2.  For instance, if we set full permissions, you would add up 2^1 (0), 2^1 (2), and 2^2 (4), resulting in the command (first 0 represents that it is a file, not a directory, you can typically omit this):
sudo chmod 0444

We get 444 because we are only setting the “first” bit of r, or “read,” to “on.”  Because this value is the third value from the right, we use 2^2, which is 4.  Make sense? I hope so!  If not please leave a comment below. Symbolic Modes: Symbolic modes are easier for some, but I have always felt you miss out on what you are really doing, and why you are doing it.  But, in the end, that is just my opinion and it is entirely up to you.  Setting permssions symbolically involves add a +’option’, such as chmod +x shared_directory.  Categories are as follows:

Reference Class Description
u user the owner of the file
g group users who are members of the file’s group
o others users who are not the owner of the file or members of the group
a all all three of the above, is the same as ugo
Operator Description
+ adds the specified modes to the specified classes
- removes the specified modes from the specified classes
= the modes specified are to be made the exact modes for the specified classes
Mode Name Description
r read read a file or list a directory’s contents
w write write to a file or directory
x execute execute a file or recurse a directory tree
X special execute which is not a permission in itself but rather can be used instead of x. It applies execute permissions to directories regardless of their current permissions and applies execute permissions to a file which already has at least 1 execute permission bit already set (either user, group or other). It is only really useful when used with ‘+’ and usually in combination with the -R option for giving group or other access to a big directory tree without setting execute permission on normal files (such as text files), which would normally happen if you just used “chmod -R a+rx .”, whereas with ‘X’ you can do “chmod -R a+rX .” instead
s setuid/gid details in Special modes section
t sticky details in Special modes section

Putting it all together:

Now let’s go through an example to illustrate this. Say you transferred a folder over from Windows to you Linux machine, and it retained some odd permissions and you cannot open it. You want to give yourself FULL access but just give other groups read and execute privileges.   We want to spread the permission not to just the folder, but also to all folders beneath the main one. The -v option below is for verbose output. Referring to what we learned above, this command can be done in the two ways discussed under the Terminal: Octal Notation Mode 

chmod 0755 -Rv /home/user/my_folder

OR Symbolic Mode:

chmod u+rwx


The POSIX system call method is befuddling and I really don’t recommend this method to anyone.  If you want to read more about it, so can do so here.


So, in nutshell that’s it!  Don’t worry if you mess up permissions, in most cases they can be undone, and if not, a Live-CD can remedy the situation in a snap.  Hope you enjoyed this How-To. Till next time, -Professor


About professorkaos64

Posted on 20130620, in How-To and tagged , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

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

You are commenting using your 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