Entry
Linux: File: Permission: Set: How to set your read/write/execute permissions? [chmod / run]
Feb 26th, 2004 18:42
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 18 September 2003 - 00:56 am ------------------
Linux: File: Permission: Set: How to set your read/write/execute
permissions? [chmod / run]
---
Method: use chmod
---
Steps: Overview:
1. -In a console type the command
chmod <permissions> <your filename>
---
You use a 3 digit number to indicate the permissions.
---
e.g.
chmod 617 myfilename
e.g.
chmod 644 myfilename
e.g.
chmod 750 myfilename
e.g.
chmod 755 myfilename
---
The first digit defines what permissions the owner (or creator) of the
file has.
The second digit defines what permissions the group the owner belongs
to (e.g. the other developers) has.
The third digit defines what permissions everybody else has.
---
Each category of permissions (read, write and execute) is assigned a
numeric value
(that is, the sum of 4, 2, 1 and 0
thus any integer number 0, 1, 2, 3, 4, 5, 6, 7)
---
Here:
Read permission is 4
Write permission is 2
Execute permission is 1
(execute permission for a directory means that the directory can be
searched)
No permission is 0
---
---
If you want the owner or creator of the file to have permission to
read, write, not execute
the file,
you assign 6 to the first digit (=4 + 2 + 0)
If you want the group of the owner or creator of the file to have
permission to
not read, not write, execute
the file,
you assign 1 to the second digit (=0 + 0 + 1)
If you want to give everybody else the permission to
read, write, execute
the file,
you assign 7 to the third digit (=4 + 2 + 1)
Thus all together this gives:
chmod 617 myfilename
---
If you want the owner or creator of the file to have permission to
read, write, not execute
the file,
you assign 6 to the first digit (=4 + 2 + 0)
If you want the group of the owner or creator of the file to have
permission to
read, not write, not execute
the file,
you assign 4 to the second digit (=4 + 0 + 0)
If you want to give everybody else the permission to
read, not write, not execute
the file,
you assign 4 to the third digit (=4 + 0 + 0)
Thus all together this gives:
chmod 644 myfilename
---
If you want the owner or creator of the file to have permission to
read, write, execute
the file,
you assign 7 to the first digit (=4 + 2 + 1)
If you want the group of the owner or creator of the file to have
permission to
read, not write, execute
the file,
you assign 5 to the second digit (=4 + 0 + 1)
If you want to give everybody else the permission to
not read, not write, not execute
the file,
you assign 5 to the third digit (=0 + 0 + 0)
Thus all together this gives:
chmod 750 myfilename
---
For example:
If you want the owner or creator of the file to have permission to
read, write, execute
the file,
you assign 7 to the first digit (=4 + 2 + 1)
If you want the group of the owner or creator of the file to have
permission to
read, not write, execute
the file,
you assign 5 to the second digit (=4 + 0 + 1)
If you want to give everybody else the permission to
read, not write, execute
the file,
you assign 5 to the third digit (=4 + 0 + 1)
Thus all together this gives:
chmod 755 myfilename
---
---
Note:
You can quickly see if a file is executable for a group.
If the digit is odd, it will be an executable
(this because the execute option has the value 1,
which is an odd number, and all the other numbers
are even. And a sum of only even numbers is always even,
but the sum of an even and an odd number is always
odd. So if the sum includes the executable option
it will the sum of (some even numbers) and an
odd number. And there is only one odd number here,
the executable option).
---
---
Or thus a quick overview of each individual 1 digit:
0 = 0 + 0 + 0 = not read + not write + not execute
1 = 0 + 0 + 1 = not read + not write + execute
2 = 0 + 2 + 0 = not read + write + not execute
3 = 0 + 2 + 1 = not read + write + execute
4 = 4 + 0 + 0 = read + not write + not execute
5 = 4 + 0 + 1 = read + not write + execute
6 = 4 + 2 + 0 = read + write + not execute
7 = 4 + 2 + 1 = read + write + execute
---
---
You can also use another accepted notation,
using:
r for read
w for write
x for execute
---
u for owner
g for group
o for everybody else
---
---
A quick way to make a file executable,
is to type:
chmod +x <your filename>
e.g.
chmod +x a.out
---
To give read and write access to the 'owner', type:
chmod u=rw <your filename>
e.g.
chmod u=rw lilo.conf
---
To give execute access to the 'group', type:
chmod g=x <your filename>
e.g.
chmod g=x a.out
---
e.g. to add read access for 'everybody else'
to the 'scd0' device,
type
chmod o+r /dev/scd0
---
---
On the console command line, type the command:
man chmod
to get more information.
---
---
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: Permission: State: Check: How to check your read/write/copy
permissions? [scd0 / chmod]
http://www.faqts.com/knowledge_base/view.phtml/aid/24430/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
----------------------------------------------------------------------