LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-21-2004, 07:45 PM   #1
Squall
Member
 
Registered: Jan 2004
Location: The land of the free and the home of the brave
Distribution: Slack 10
Posts: 239

Rep: Reputation: 31
Pretty confused about using numbers for file permissions


I've always been a little bit fuzzy on the topic.
I can type chmod a+w file fine, but I don't understand how to use numbers to represent it. If you are helping me, please don't just say "chmod 777" will give everyone rwx, I want to know how this representation system works.
 
Old 04-21-2004, 08:30 PM   #2
cnirrad
LQ Newbie
 
Registered: Mar 2001
Distribution: Fedora
Posts: 7

Rep: Reputation: 0
Basically, you need to think of each number as a binary number. So a 7 in binary is actually 111. In this form, each position represents a permission with a 1 representing the permission as being granted and 0 as not allowed. The positions for the permissions are (in this order) read, write, execute.

So you can see that a 7 grants permissions for read, write and execute. A 6 (binary form 110) would grant permissions for reading and writing.

Now, back to the decimal form....these three positions are for the owner, members of the group, and lastly everyone else. This is why 777 translates into read, write and execute permissions for the owner, members of the group and all others. 700 would give all permissions, but only to the owner of the file.

Clear as mud?
 
Old 04-21-2004, 08:45 PM   #3
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
This is all explained in 'man 1 chmod':
Quote:
A numeric mode is from one to four octal digits (0-7), derived by adding up the bits with values 4, 2, and 1. Any omitted digits are assumed to be leading zeros. The first digit selects the set user ID (4) and set group ID (2) and sticky (1) attributes. The second digit selects permissions for the user who owns the file: read (4), write (2), and execute (1); the third selects permissions for other users in the file's group, with the same values; and the fourth for other users not in the file's group, with the same values.
But I can try to rephrase it.
The numbers are interpreted as three bitfields (those 3 numbers; 7, 7 and 7 in your case) each containing three bits.

To figure out what those numbers mean, you have to convert them to bit representation.
For example the number 7 is '111' in binary (1*2^2+1*2^1+1) , (Equally similar to decimal representation of for example value 275 is 2*10^2+7*10^1+5 [Here the '^' means rising to power].
So, what does the bitfield '111' tells us? It means that reading, writing and executing flags are all on. So the original number serie 777 means that reading, writing and excuting are allowed for for owner, group and others.

Other example: What does mode 644 mean?
Interpreting the 6: '110' (that is 1*2^2+1*2^1+0)
Interpreting the 4: '100' (that is 1*2^2+0*2^1+0)
Now in '110' the reading and writing flags are on, but execution is not and in '100' reading is on, other flags off. So, the modeline 644 means that owner has read and write permissions and group and others have only reading permission.

And to the other way around; how to set for example permissions so that user can execute the file, group can read and execute it and others can do nothing with it?
Way 1:
Convert the idea to binary number and it to decimal
How? User: '001', group: '101', others: '000', so the mode is 150

Way 2:
Remember (or look from the manpage) that: read (4), write (2), and execute (1).
That is: set only execute:1, to set read and execute: 4+1, To set nothing: 0.
So we got the 150 again.
 
Old 04-21-2004, 09:17 PM   #4
RockmanExe
Member
 
Registered: Aug 2003
Distribution: Mandriva, Slackware
Posts: 265

Rep: Reputation: 30
to complete ToniT's post, read this, which is very neat and quite understandable

http://www.linuxquestions.org/questi...ticle&artid=20

cheers
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] file locations and version numbers politik Linux - Newbie 2 08-21-2005 09:32 PM
numbers as file owners stabu Linux - General 3 04-27-2004 12:29 PM
Checking a file for numbers chrisk5527 Linux - General 1 09-12-2003 08:50 AM
I'm confused - Crontab and Access Permissions Newman_SCO Linux - Newbie 5 09-03-2003 08:28 PM
file version numbers tjones11 Programming 2 03-15-2002 12:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration