Going to start with this as it seems to be a fundamental concept central to figuring the rest of this stuff out. And also because itâs a fairly simple concept to grasp.
If you view the files in a directory by typing ls -l, you will see a sequence before the file name as shown below:
root@servername:/var/www# ls -l
total 16
drwxr-xr-x 3 root root  4096 2012-01-24 00:55 .
drwxr-xr-x 15 root root  4096 2012-01-23 04:36 ..
-rw-r--r-- 1 root root  200 2012-01-23 05:25 index.html
drwxr-xr-x 4 root developers 4096 2012-01-24 00:55 websiteurl.com
Now that may seem like a lot of information, but itâs really not. Letâs break it down:
On the first line, you can see that I am logged in as root on my server and inside the folder /var/www. Now at this prompt, I typed ls -l to view the contents of this directory in detail. I was then shown the contents. The first two rows are just . and .. which we can ignore for now (just know that they go back to the root folder and parent folder respectively).Â
So that leaves us with two things in this directory, index.html and websiteurl.com - One is a file and one is a directory. Letâs have a look at them broken up:
 So you can see that directory listing is displayed in 7 columns.Â
Permissions - This is broken up into 4 parts. On the index.html file the permissions column has the following entry: â-rw-r--r--â. This is essentially a 10 character string. The first character position is â-â for index.html and âdâ for websiteurl.com -- This is because the first character tells you if this is a file or a directory. When it is a file, it is left blank, and displays a âdâ in case of directory.
The next three characters will tell you what permissions the user (or owner) of the file has. They are depicted by rwx in that order. So, in this case we have ârw-â on index.html which means that the owner has read and write access but not execute.
After the userâs permissions come the three characters which tell you what permissions the âgroupâ assigned to that file or directory has. In the case of index.html we see that the group has âr--â which means that they only have read access and cannot write or execute.
The last three characters tell you what rights others (or everyone) has. In the case of index.html again we see that it is only read access âr--â.
Directories - Tells you how many directories are within this particular folder.
Owner - Displays the name of the owner of the file.
Group - Displays the name of the group assigned to this file or directory.
Size - Displays the size of the file or folder.
Date - Date and time of the last update made to said file or folder.
Directory or file - Filename or directory name.
So once we know this information, the jargon that is displayed when you type ls -l doesnât seem all that intimidating anymore. Now we can jump into âmodifyingâ these permissions.
There are three commands that weâll discuss here for all things permissions related. They are chmod, chown and chgrp.
chmod - Modifies permissions
chown - Changes the owner of the file
chgrp - Changes the group of the file
Simple? I thought so. You can check out the different arguments you can pass with these commands by typing âman chmodâ to see the manual. I am going to use my favorite one in the examples below, which is -R. This basically means ârecursively apply this command to all the files and sub-folders within this directoryâ.
So, for this example, I went to my /var/www folder and created a file called test.txt by typing âvi test.txtâ and then inserted the text âThis is a test fileâ and saved.
This is what the file looks like when I type ls -l:
-rw-r--r-- 1 root root   16 2012-01-24 06:31 test.txt
Now I will change the permissions for this file. I want to give:
Owner - Read, write, execute
chmod ug=+x (Give âUserâ i.e. owner and âGroupâ execute permission)
Now when we do ls -l, our test.txt file is as such:
-rwxr-xr-- 1 root root   16 2012-01-24 06:31 test.txt
More more details on chmod and itâs literally hundreds of possibly uses, I highly recommend this tutorial. (http://catcode.com/teachmod/chmod_cmd.html)
chown is far simpler to use. Simply type âchown username file-or-directory-nameâ. This will change the User (owner) of that file.
chgrp is similar in use. Simply type âchgrp groupname file-or-directory-nameâ. This will change the Group of that file.
That just about covers the basics. Please check out the reference URL above to polish up on the details.