LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-10-2012, 12:00 AM   #1
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Rep: Reputation: 15
read write access


ls -l shows. Read write access of file .
How do i calculate access code in digits. By looking at ls -l?
 
Old 04-10-2012, 12:17 AM   #2
Zssfssz
Member
 
Registered: Sep 2011
Location: Las Vegas!
Distribution: Ubuntu n' Flavors, ReactOS, MINIX3, FreeDOS, Arch
Posts: 339

Rep: Reputation: Disabled
Could you tells us what you are tring to do?
What's this accsess code thing?
 
Old 04-10-2012, 12:34 AM   #3
yoK0
LQ Newbie
 
Registered: Apr 2012
Distribution: Slackware, CentOS
Posts: 29

Rep: Reputation: 0
4 = read (r)
2 = write (w)
1 = execute (x)
0 = no permission (-)


rwxrw-r--

rwx = 4+2+1 = 7
rw- = 4+2 = 6
r-- = 4

rwxrw-r-- can also be written in octal as 764

eg. when you change file permission you can use

chmod ug+rw <some_file> or chmod 660 <some_file> as result you get rw-rw----
 
Old 04-10-2012, 12:58 AM   #4
Zssfssz
Member
 
Registered: Sep 2011
Location: Las Vegas!
Distribution: Ubuntu n' Flavors, ReactOS, MINIX3, FreeDOS, Arch
Posts: 339

Rep: Reputation: Disabled
Ohh the stuff used with chmod (sorry I use numbers not the letters and call them Ids not accsess code).
That kind of stuff is found in the filesystem not the file so it might be hard...
I don't know... There might be an option in chmod or file but otherwise I think it might be filesystem specific...
I'm sorry this is not my best area of knowledge
Edit: ln -l -v would make it verbose and spit out everything, try that (if -v ends up being version try --verbose)

Last edited by Zssfssz; 04-10-2012 at 01:00 AM.
 
Old 04-13-2012, 09:18 AM   #5
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by yoK0 View Post
4 = read (r)
2 = write (w)
1 = execute (x)
0 = no permission (-)


rwxrw-r--

rwx = 4+2+1 = 7
rw- = 4+2 = 6
r-- = 4

rwxrw-r-- can also be written in octal as 764

eg. when you change file permission you can use

chmod ug+rw <some_file> or chmod 660 <some_file> as result you get rw-rw----
There is no space in rwxrx.
So this should have been 4+2+1+4+2=13.
is not it?
Could you please recheck your maths.Please note there is no gap.
 
Old 04-13-2012, 09:32 AM   #6
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,504

Rep: Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490
There's nothing wrong with the math. You can make the change by EITHER using numbers OR by using letters NOT by mixing them. In the example posted earlier:

Quote:
chmod ug+rw <some_file> or chmod 660 <some_file> as result you get rw-rw----
the ug would be the user/group and the + would add the rw (read/write) permissions for the user/group. That can also be written as: chmod 660. Using numbers in place of letters is usually easier faster. Using either of these specific commands would show the output below with the ls -l command:

Quote:
rw-rw----
The post above by yoK0 explains what each option means. If you don't understand, there are numerous sites explaining it in excruciating detail or you could search the LQ forums.
 
Old 04-13-2012, 09:41 AM   #7
TommyC7
Member
 
Registered: Mar 2012
Distribution: Slackware, CentOS, OpenBSD, FreeBSD
Posts: 530

Rep: Reputation: Disabled
chmod's permission settings written numerically make use of binary. What yok0 told you wasn't wrong, but your interpretation of it is incorrect. Here are a few guidelines to help:
Quote:
1. Binary is read from left to right.
2. There are only two numbers: 0 and 1, two numbers hence BInary, much like BIcycle because it only has two wheels, or BIpolar, etc. etc. you get the point.
3. The first number (far left) is is 2^0. If it's a 1, that 2^0 is used (and equals 1), otherwise if it is 0, it is 0 no matter what 2^x it is. The second number is (second from the left) is 2^1, third is 2^2, and so on and so forth.
Here's an example:
1110
2^0 is off, 2^1 is on, 2^2 is on and 2^3 is on. Therefore 0 + 2 + 4 + 8 = 14.

Now let's see how chmod looks at this:
rwx
111

Now we know that rwx = 7. Of course there's 3 parts to Unix permissions: owner, group and other. Let's do some more math (I really love math): We want chmod to set these settings:
rwx|r-x|rw-
111|101|110

The pipes are to help you identify the splits. Starting from the left:
Other:
Code:
2^0 is off, 2^1 is on, 2^2 is on.
0 + 2 + 4 = 6.
Group:
Code:
2^0 is on, 2^1 is off, 2^2 is on.
1 + 0 + 4 = 5.
Owner:
Code:
2^0 is on, 2^1 is on, 2^2 is on.
1 + 2 + 4 = 7.
So if I wanted the settings above I would use: chmod 756

If that doesn't help, refer to yancek's post.

Edit 1: Please also note, that the numerical method will completely reset the settings and use the ones you specify. The other adds or removes settings as they're currently set. So using yancek's post as an example:

chmod 660 sets rw-rw---- BUT chmod ug+rw ADDS read-write access to the user+group, so if I used:

chmod 110, the user and groups that have access to that file are only able to execute it (2^0 is on). If I use "chmod ug+rw" on that file, I get read-write access too so instead of being:

--x--x--- it changes to rwxrwx---.

Edit 2: Organized the post a bit more.

Last edited by TommyC7; 04-13-2012 at 09:55 AM.
 
Old 04-13-2012, 02:29 PM   #8
yoK0
LQ Newbie
 
Registered: Apr 2012
Distribution: Slackware, CentOS
Posts: 29

Rep: Reputation: 0
Quote:
Originally Posted by Volcano View Post
There is no space in rwxrx.
So this should have been 4+2+1+4+2=13.
is not it?
Could you please recheck your maths.Please note there is no gap.
You do not add all the numbers. There are three groups
user/owner ||| group ||| others
rwx ||| rw- ||| r--

When you're using numbers to express permissions each number represents each group of permissions.

So,
rwx ||| rw- ||| r--
4+2+1 ||| 4+2 ||| 4
7 ||| 6 ||| 4
You add only numbers from each group and not all of them.

Last edited by yoK0; 04-13-2012 at 02:32 PM.
 
Old 04-15-2012, 03:12 AM   #9
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by yoK0 View Post
You do not add all the numbers. There are three groups
user/owner ||| group ||| others
rwx ||| rw- ||| r--

When you're using numbers to express permissions each number represents each group of permissions.

So,
rwx ||| rw- ||| r--
4+2+1 ||| 4+2 ||| 4
7 ||| 6 ||| 4
You add only numbers from each group and not all of them.
Thats nice. I understand this now.

Could you please why you said r = 4 , w =2 , x=1

How do You arrive read r =4 and write w =2 and execute x =1 . Where from you get this numbers ? whats the logic here ?
 
Old 04-15-2012, 03:23 AM   #10
TommyC7
Member
 
Registered: Mar 2012
Distribution: Slackware, CentOS, OpenBSD, FreeBSD
Posts: 530

Rep: Reputation: Disabled
Quote:
Originally Posted by Volcano View Post
Thats nice. I understand this now.

Could you please why you said r = 4 , w =2 , x=1

How do You arrive read r =4 and write w =2 and execute x =1 . Where from you get this numbers ? whats the logic here ?
http://www.linuxquestions.org/questi...1/#post4651875

Mathematics and an understanding of binary.
 
Old 04-15-2012, 03:53 AM   #11
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by TommyC7 View Post
http://www.linuxquestions.org/questi...1/#post4651875

Mathematics and an understanding of binary.
OK. Thanks

What is command to check whether a user is a owner / other / group user ?

Suppose I know a userid "john". Is it possible to know whether this userid is a owner / other / group user ?

How do you find this ?

Last edited by Volcano; 04-15-2012 at 04:16 AM.
 
Old 04-15-2012, 04:17 AM   #12
TommyC7
Member
 
Registered: Mar 2012
Distribution: Slackware, CentOS, OpenBSD, FreeBSD
Posts: 530

Rep: Reputation: Disabled
I don't understand how you've been with LQ.org for 7 years and didn't learn binary at least in that time, but I'll help. As previously stated in my post already, binary only consists of two numbers: 0 and 1. Bicycles only consist of two wheels. So bi means two. With those two numbers, 0 is off and 1 is on. So let me ask the question this way:

Do you want to set the "readable (by owner)" switch to on?
Do you want to set the "writable (by owner)" switch to on?
Do you want to set the "executable (by owner)" switch to on?

Do you want to set the "readable (by group)" switch to on?
Do you want to set the "writable (by group)" switch to on?
Do you want to set the "executable (by group)" switch to on?

Do you want to set the "readable (by others)" switch to on?
Do you want to set the "writable (by others)" switch to on?
Do you want to set the "executable (by others)" switch to on?

1 for yes, 0 for no. And as many people here have pointed out already -- these options are separated into 3 groups so instead of having to do chmod 128 or some other crazy power of two, you only need to type 7 for all permissions.

Notice that yak0's numbers for r=4, w=2 and x=1 can all be solutions to 2^n. If you need help finding out what n equals, just use logarithms.

So, to test what would be 101101 in binary?
 
Old 04-15-2012, 04:26 AM   #13
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You can use the find command to locate files owned by a particular user.
find <dir> -user <username>

The user of a particular file can be extracted from its "ls -l" line. You can also use "stat -c "%U" <filename>"
 
Old 04-15-2012, 05:09 AM   #14
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
You can use the find command to locate files owned by a particular user.
find <dir> -user <username>
No. I want just the opposite. I know a file name. I want to know who is its owner. Is it not possible to find out ?

because a owner only can change file permission ...right ?

Last edited by Volcano; 04-15-2012 at 05:14 AM.
 
Old 04-15-2012, 05:11 AM   #15
TommyC7
Member
 
Registered: Mar 2012
Distribution: Slackware, CentOS, OpenBSD, FreeBSD
Posts: 530

Rep: Reputation: Disabled
Please don't just read a part of our posts:

Quote:
Originally Posted by jschiwal View Post
You can use the find command to locate files owned by a particular user.
find <dir> -user <username>

The user of a particular file can be extracted from its "ls -l" line. You can also use "stat -c "%U" <filename>"
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Read Write access to a iso9660 filesystem..mount a .iso image as read write ceazar123 Linux - Newbie 16 09-01-2010 09:07 AM
Read Write access to a iso9660 filesystem..mount a .iso image as read write ceazar123 Linux - General 2 08-26-2010 03:32 PM
vsftpd read access for user accounts but needs write access ncsuapex Linux - Server 2 04-23-2010 10:51 AM
No write or read access to anything I mount Romanus81 Slackware 7 04-13-2008 07:19 AM
read write access phoenix_wolf Linux - Newbie 2 12-05-2004 09:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:40 AM.

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