RSS

Permissions in *nix

24 Jan

I often need to change permissions on files in Linux but for some reason have trouble remembering octal permissions. I hope to give a brief tutorial on octal permissions and chmod.

Many times when I need to chang a files permissions it is becaues I need to execute it. This is fairly trivial with chmod. All one needs to do to make a file executed able for himself is to run the command chmod +x ./path/to/file. Infact there you can to a lot more than just making a file executable with arguments. If you want to know more about that take a look at chmods man page, because I’m notgoing to cover it.

If one wants to change permissions for more than just himself or wants to change many things at once the easiest way is to use octal permissions codes (I’m sure thats not the right terminology). The syntax for these codes, with chmod, is chmod <code> /path/to/file. The codes are pretty easy. All you have to do is remember three numbers and what they do: 1 sets the file to executable, 2 sets the file to writable, and 4 makes the file readable. These numbers can be added to combine their functionality. 3(1+2) makes a file executable and writable; 6(4+2) makes a file both readable and writable. These numbers can be added in anyway up to 7(1+2+4). 0 sets the file to no permissions.

I said that you could change permissions for multiple people as well as just the read-write-excitability, but so for I haven’t said how. Well, its really quite simple. to change permissions for more than just one’s self one uses more than one number. Order is important, it can’t read your mind. You can change permissions for yourself, your group, and everyone else(no one in particular). So, for exapmle lets change a file so that I can execute it but no one else can. I would run the command chmod 100 /path/to/file. If I want everyone in my group to also be able to use the file I will use chmod 110 /path/to/file. chmod 111 /path/to/file would allow every one on the system to execute the file. So the order is user, group, other. Remember this starts from right to left so if you just use chmod 1 /path it is like using chmod 001 /path.

Hopefully this makes sense to someone; if not let me know in the comments. I did say I only hoped to give a tutorial, not that it was going to be a successful event.

Advertisements
 
Leave a comment

Posted by on January 24, 2008 in Uncategorized

 

Tags: ,

Leave a Reply

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

WordPress.com Logo

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

 
%d bloggers like this: