faqts : Computers : Operating Systems : Linux

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

27 of 41 people (66%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

Linux: Permission: Get: How check current read/write/copy permissions? [device / chmod / file]

Feb 26th, 2004 20:30
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 18 September 2003 - 00:36 pm ------------------

Linux: Permission: Get: How check current read/write/copy permissions? 
[device / chmod / file]

---

In general:

---

in case of a file, you can check the currently permission settings, by
typing the command:

 ls -l <your filename>

---

in case of a directory, you can check the currently permission 
settings, by
typing the command:

 ls -l <your directory>

---

in case of a device (which is by design also represented as a file),
you can check the currently permission settings, by typing the command:

 ls -l <your device>

---
---

e.g.

To check the current permission settings of the file 'ddd.c', type the
command on the console command line:

 ls -l ddd.c

---

a typical result from this is showing the current
permissions for this file

 -rw-r--r-- 1 root root 11, 57 Dec 3 10:19 ddd.c

---
---

e.g.

To check the current permission settings of the (executable) file
'a.out', type the command on the console command line:

 ls -l a.out

---

a typical result from this is showing the current
permissions for this file

 -rwxr-xr-x  1 root root 11540  Dec 3 11.50 a.out

---
---

e.g.

To check the current permission settings of the directory
'/home', type the command on the console command line:

 ls -l /home

---

a typical result from this is showing the current
permissions for this directory

 drwx------  13 john john 4096  Dec 3 14.29 a.out

---
---

e.g.

To check the current permission settings of the SCSI diskdrive 'scd0',
type the command on the console command line:

 ls -l /dev/scd0

---

a typical result from this is showing the current
permissions for this SCSI disk:

 brw------ 1 root disk 11, 0 Jan 30 2003 scd0

---
---

How could this be interpreted?

---

If you look at the general scheme below, it shows
that:

---

1. The first bit is 'b', or thus 'B'inary or thus
   a device

---

2. The second bit is 'r', or thus 'R'ead.

Thus you have 'r', or thus read permission to the
directory where this file 'scd0' is stored
(by default the '/dev' directory).

---

2. The third bit is 'w', or thus 'W'rite.
Thus you have write permission.

---

3. There exists 1 link for this file

---

4. The login name is 'root'

---
---


                             +-> total amount of links for this file
                             | +-> login name of the owner / creator
                             | |      +-> total amount of bytes
                             | |      |   for this file
                             | |      |   +-> creation date
                             | |      |   |      +-> creation time
                             | |      |   |      |     +-> name for it
                             | |      |   |      |     |
1 2 3 4 5 6 7 8 9 10         | |      |   |      |     |
- r w - r - - r - -          1 myself 182 Nov 11 15:25 myfile.dok

bit1 = directory (file is directory or not)

---

bit2 = read permission owner
bit3 = write permission owner
bit4 = execute (or copy) permission owner

bit5 = read permission for the other members in same group
bit6 = write permission for the other members in same group
bit7 = execute (or copy) permission for the other members in same group

bit8 = read permission for the other members in all other groups
bit9 = write permission for the other members in all other groups
bit10 = execute (or copy) permission for the other members in all 
other groups

---

d = directory

b = device

---

r = read permission

w = write permission

x = execute permission

---

[book: see also: Brown, P. J. - begin with Unix - ISBN: 90-6789-026-X -
 p. 64]

---
---

Note:

Conversion to the chmod value:

As you might want to know quickly what the chmod 3 digit value is, you
can add the 4, 2 and 1 values of the three corresponding groups.

---

e.g.

1 2 3 4 5 6 7 8 9 10
- r w - r - - r - -

or thus replacing by zeros and ones:

0 1 1 0 1 0 0 1 0 0

with corresponding values:

  4 2 1 4 2 1 4 2 1

so looking only at the values with a '1',
and adding these for each group, this becomes:

  4+2+0 4+0+0 4+0+0

or thus:

  6     4     4

So the chmod value of this file is 644.

So if you should have typed:

 chmod 644 yourfilename

it should show the same values, after doing
a

 ls -l yourfilename

---
---

Tested in Linux Red Hat v9

---
---

Internet: see also:

---

Linux: Permission: View: How to view your read/write/copy permissions? 
[scd0 / chmod]
http://www.faqts.com/knowledge_base/view.phtml/aid/24428/fid/107

---

Linux: File: Permission: Set: How to set your read/write/execute 
permissions? [chmod / run]
http://www.faqts.com/knowledge_base/view.phtml/aid/24443/fid/107

---

C++: Compile: Operating system: Linux: How to compile C or C++ program 
on Linux? [run / hello world]
http://www.faqts.com/knowledge_base/view.phtml/aid/26744/fid/107

----------------------------------------------------------------------