[Ilugc] One Day One GNU/Linux Command (CHMOD)

  • From: sbharathi@xxxxxxxxxxxxx (Bharathi Subramanian)
  • Date: Tue Jun 17 09:50:41 2008

One Day One GNU/Linux Command
=============================

chmod -- CHange file access permission MODes

Summary:

chmod is used to change the permission of the file(s) or Dir(s).  

Interpretation of one line of ls -l command output :-

-rwxr-xr--  1 sbharathi   dsg   10 Feb 14 15:00 myfile
^\ /\ /\ /    \       /   \ /
| V  V  V      ---+---     V
| |  |  |         |        `-- Group
| |  |  |         `-- User/owner
| |  |  `-- Others 
| |  `----- Group      
| `-------- User/owner
`---------- d=directory, -=file, l=link, b=blockdev, c=chardev, etc

There are three kinds of permissions that a user can have for a file:

r) Permission to Read the file.  For Dir, this means permission to
   list the contents of the Dir.

w) Permission to Write to (change) the file.  For Dir, this means
   permission to create and remove files in the Dir.

x) Permission to eXecute the file (run it as a program). For Dir, 
   this means permission to access files in the Dir.

There are three categories of users who may have different permissions
to perform any of the above operations on a file:

u) The file's owner.

g) Group users who are in the file owner's group.

o) Others or Everyone else.

Permissions are stored internally as an integers.

Integer -- Notation -- Meaning

Basic:
 1           x         eXecute
 2           w         Write
 4           r         Read

Ext:
 3 (2+1)     wx        Write and eXecute
 5 (4+1)     rx        Read and eXecute       
 6 (4+2)     rw        Read and eXecute
 7 (4+2+1)   rwx       Read, Write and eXecute


Examples:

$ chmod 777 myfile -- All permission to all. Here permissions are  
                      given in numerical format.

$ chmod 755 f1 f2  -- setting all permissions to owner and read & 
                      Execute permissions to group and others.

$ chmod u=rwx,g=rx,o=rx myprg  -- Same as above. But here permissions 
                                  are given in symbolic format.

$ chmod u+x,g+r,o-rwx myprg -- Add Exec permission to owner, Add Read
                               permission to group and Remove all 
                               permission for others.

$ chmod u-x,go-rx myfile -- Remove Exec permission for owner and Remove 
                            Read & Exec permissions for group & others.

$ chmod -R 755 mydir  -- Set the permission for files & Dirs recursively.

$ chmod --reference=f1 f2 -- Set f1's mode to f2.

$ chmod -c 755 myfile -- Verbose but report only when a change is made.

$ chmod -v 754 myfile -- Verbose output for every file processed.

NOTE: `chmod' never changes the permissions of symbolic links.

Read: man chmod / info chmod

HTH :)
-- 
Bharathi S

Other related posts: