Home > Unix > UNIX – Lesson 017 – chmod command in symbolic-mode and in absolute-mode

UNIX – Lesson 017 – chmod command in symbolic-mode and in absolute-mode


chmod
The “chmod” command (abbreviated from change mode) is a shell command to change filesystem modes of files and directories
Permissions can only be changed by the owner (or root user).
There are two ways to use the chmod command:

  • symbolic-mode
  • absolute-mode

=================================================================================

chmod command in symbolic-mode

A symbolic mode specification has the following format:

Syntax :
chmod [options] symbolic-mode files/directories

Key argument :

  • -f    Force. chmod will  not  complain  if  it  fails  to  change the mode of a file.
  • -R    Recursively descends through  directory  arguments, setting  the mode for each file as described above. When symbolic links are encountered, the mode of the target file is changed, but no recursion takes place.

Where symbolic-mode is [who[operator]permission]

  • who         user, group, or other
  • operator         + (add), – (subtract), = (set equal to)
  • permission     read, write, execute

Examples

Starting from original permissions for “myfile” file equal to
-rw-r–r–   1 xarabas users         22 Feb 20 14:53 myfile

Running the following command:
chmod u+x,g+x,o+x myfile OR       chmod +x myfile
The final result is: rwxr-xr-x     myfile

Starting from the previous result and executing this command:
chmod g=x,o= myfile
The final result is: rw—x—     myfile

Starting from the previous result and executing this command:
chmod u+x,g=rx,o-r myfile
The final result is: rwxr-x—     myfile

=================================================================================

chmod command in absolute-mode

The chmod command also supports a numeric (octal) representation. This representation is
obsolete, but it’s a commonly used form. Convert each group of permissions into
appropriate numeric representation

Syntax :
chmod [options] absolute-mode files/directories

Key argument :

  • -f    Force. chmod will  not  complain  if  it  fails  to  change the mode of a file.
  • -R    Recursively descends through  directory  arguments, setting  the mode for each     file as described above. When symbolic links are encountered, the mode of the      target file is changed, but no recursion takes place.

Where absolute-mode is:

  • Read = 4
  • Write = 2
  • Execute = 1
  • 400     Allow read by owner.
  • 200     Allow write by owner.
  • 100     Allow execute (search in directory)  by owner.
  • 700     Allow read, write, and execute (search) by owner.
  • 040     Allow read by group.
  • 020     Allow write by group.
  • 010     Allow execute (search in directory)  by group.
  • 070     Allow read, write, and execute (search) by group.
  • 004     Allow read by others.
  • 002     Allow write by others.
  • 001     Allow execute  (search in directory)  by others.
  • 007     Allow read, write, and execute (search) by others.

Examples:

Starting from original permissions for “myfile” file equal to:
-rw-r–r–   1 xarabas users         22 Feb 20 14:53 myfile

Running the following command:
chmod 640 myfile
The final result is : -rw-r—–     myfile

Executing this command:
chmod 777 myfile
The final result is:-rwxrwxrwx     myfile

Executing this command:
chmod 000 myfile
The final result is: ———-     myfile

Executing this command:
chmod 755 myfile
The final result is: -rwxr-xr-x     myfile

Categories: Unix
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: