On the Net

|Main Blog|Yearning|  

Words of God


About Linux News and OpenSource




and below are my posts....


Wednesday, November 30, 2005

The CHMOD command

Note: $ signifies user prompt, # signifies root prompt


The chmod command changes permissions on files and directories. Type $man chmod in your linux console for further info. If you would like to see what permission a file has, you may type in your console the command
$ls -l testfile.txt
-rw-rw-r– 1 ken ken 0 May 16 11:21 testfile.txt

# the file has a permission of 664… see table below

Table 001
Illustrates the eight possible combinations of numbers used for changing permissions.
Decimal—–Binary—–Permissions
0 000 none
1 001 –x
2 010 -w-
3 011 -wx
4 100 r–
5 101 r-x
6 110 rw-
7 111 rwx

The symbolic notation for chmod is as follows: r = read; w = write; x = execute; u = user;
g = group; o = others; a = all.

ex. for chmod command

$chmod 777 testfile.txt - would make the permission of the file rwx-rwx-rwx

$chmod g-x testfile.txt - would change the file permission to rwx-rw-rwx

the command g-x removes the x permission to the g(group)

$chmod g+x testfile.txt - would again add the x permission to the group rwx-rwx-rwx

In MO, its easier to remember and to use symbolic notation to add or remove a file permissions.

$chmod og-x -R /home/user/bin - would remove all the x permission on other users and the group on all the
files inside the /home/user/bin directory - rwx-rw-rw assuming the original file permission was 777 or rwx-rwx-rwx

reference book: UNIX Shells by example 4th Edition

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home