Understanding File and Folder Permissions (POSIX) on Linux and Mac OS X (using chmod)

(0 votes, average 0 out of 5)

Linux and Mac OS X both use a POSIX-compatible type of filesystem. This has to do with the way files are accessed by their owner and others. Files and folders have permissions for 3 different types of users:

  • Owner: this is the user who owns the file or folder
  • Group: this is the permissions for any user in the group that the file belongs to
  • Others: this is the permissions for all other users who don't fall into one of the two above categories

For each of these types of users, there are 3 different permissions which can be either granted or not granted, they are:

  • read (4) - gives that type of user the ability to read the file
  • write (2) - gives that type of user the ability to write to the file
  • execute (1) - gives that type of user the ability to execute the file as a program

Each of these types of permissions has an octal number associated with it (the number in parenthesis after it). To assign a file or folder more than one permission, add these numbers together. For example, to make a file both readable and writeable it would have the value 6 (4 + 2 = 6). Here's a list of all of the possible combinations:

 

0 --- no permission
1 --x execute 
2 -w- write 
3 -wx write and execute
4 r-- read
5 r-x read and execute
6 rw- read and write
7 rwx read, write and execute

 

 

The owner, group, and others each a digit to define permission for that type of user. For example a file or folder which has read, write, and execute permission by the owner, read and write permission by the group, and read permission by others would have to be 764 (rwxrw-r--). Similarly a file which is readable and writeable by the owner and group only would be 660 (rw-rw----). To view a file or folder's current permissions, use the ls command with the -l flag:

 

$ ls -l
-rw-r--r-- 1 user group      6644 2010-07-09 21:49 grep.py
drwxr-xr-x 3 user group      4096 2010-04-16 00:49 handbrake
-rw-r--r-- 1 user group      2773 2010-05-28 02:19 info.txt
-rw-r--r-- 1 user group      4542 2010-04-28 16:14 picture.png
 

 

 

To change the permissions of a file, use the chmod command followed by the octal permissions followed by the filename. For more information, see this article on common commands. Here is a brief example:

 

user@computer:~ $ ls -l winetricks
-rw-r--r-- 1 user group 161664 2010-05-26 19:44 winetricks
user@computer:~ $ chmod 775 winetricks
user@computer:~ $ ls -l winetricks
-rwxrwxr-x 1 user group 161664 2010-05-26 19:44 winetricks
 

 

To recursively change the permissions on a set of files and folders, use the -R flag: chmod -R 775 thedirectory/ .

 

Partner Links:
Last Updated on Saturday, 14 August 2010 19:48  
Related Articles

» How to Select the First/Last Sibling in XSLT

From my experiences with using XSL to transform XML documents, I frequently find the need to test the name of either the sibling directly following or directly preceding a given node.  Unfortunately, there is not XPATH expression that provides this functionality.  The following code should give you what you are looking for, however.Check to see if the first preceding sibling is "car":<xsl:if test="name(preceding-sibling::*[1]) = 'car'"><!-- code to execute...

» Combine MP4/M4V Files in Linux/Ubuntu

You may want to combine multiple mp4/m4v video files into one continuous video. In order to do this, you need to install the gpac library of programs onto Ubuntu. Open up Terminal and run:sudo apt-get install gpac This will install the gpac library. One of the programs included with it is MP4Box, which you can use to concatenate the video files. If you are using 64 bit Linux or get an error like MP4Box: error while loading shared libraries: libgpac.so: cannot open shared object file: No such...

» Using Cookies to Save Data in PHP

Cookies are a useful way to save information, for example a user preference or login session locally on the client's machine. PHP makes creating and accessing cookies very easy. To create a cookie called myCookie with the value hello,world, simply add the following line of PHP code:$expireTime = 60 * 60 * 24 + (); // 1 day("myCookie", "hello,world", $expireTime); This data will then be available the next time the user loads that particular page. To access the cookie at a later date, use the...