Changing Linux File Permission


Listing 2.0 Examining file permission with ls


   $ ls -l

   total 1641

   - r w - r - - r - -  1  craig  users 8255 May 17 14:09 fig2-1.gif

   - r w - r - - r - -  1 craig  craig 1349 May 3 2000 trace.txt

   .. . . . . . . ...

   . . .. ... . .

   - r w - r- - r - -   1  craig  11756  Apr 24 19:32  fig9-4.gif


The permissions can be viewed as three (3-bit) numbers.    r is 4 (binary 100), w is 2 (binary 010) and x is 1 (binary 001).   Thus, the permission granted to the owner in Listing 2.0 above is 6 (rw-), and the permissions granted to the group and to the world are 4 (r - -) for a file permission setting of 644.


chmod (change mode)


use the chmod (change mod) command to change the permissions for a file.   Permission can be defined on the chmod command line in either numeric or symbolic formats.

 

  for example: 

 

  [root] $ ls -l trace.txt

 

  - r w - r - - r - -  1  craig  craig  1349  May 3 2000  trace.txt

 

  [root] $ chmod g+w, o-r trace.txt

 

  [root] $ ls -l trace.txt

 

  - r w - r w - - - -  1  craig  craig  1349  May 3 2000  trace.txt

 

  Note:

1st ls command 

   where owner = read & write, group = read, world = read only

chmod command 

   g+w tells chmod to use the current group permissions and add write permission

   o-r tells chmod to use the current world (or other) permissions and subtract read permission

2nd ls commnd 

   show's the effect that this chmod command has on the trace.txt file permission