Linux

chmod command for linux tutorial and Examples

What is chmod Linux command

chmod command or “change mode command”, and as that name implies, the chmod command is used to change the mode of Unix/Linux files.

In other words it is used to define the way a file can be accessed.

chmod command Syntax

    
     chmod options permissions “filename or directory”

    
   

chmod sections description :

  • Options :the following table describe the option list
    Option Description
    -f, –silent, –quiet suppress most error messages
    -v, –verbose output a diagnostic for every file processed
    -c, –changes like verbose but report only when a change is made
    -c, –reference=RFile use RFile’s mode instead of MODE values
    -R, –recursive change files and directories recursively
    –help display help and exit
    –version output version information and exit
  • Permissions Using Numeric mode :The format of a numeric mode is ‘augo‘ ,A numeric mode is from one to four octal digits (0-7),to set permission you pass the numbers permission to owner group everyone for example chmod nnn is setting permission n to owner and the second n to group and third n to everyone (n is the numeric mode that we will describe bellow) :
    • 4 maps for “read
    • 2 maps for “write
    • 1 maps for “execute
    • 0 maps for “no permission.”
    • 7 is combination of permissions 4+2+1 (read, write, and execute)
    • 6 is combination of permissions 4+2+0 (read, write, and Not execute)
    • 5 is 4+0+1 (read, no write, and execute).
  • Permissions Using symbolic Permissions Notation :The letters u, g, and o mapping to “user“, “group“, and “other” in order. and the letters “r“, “w“, and “x” stand for “read“, “write“, and “execute“, respectively.and you will need to use The equals sign (=) between the u,g,o and rwx as example:
    chmod u=rwx,g=rx,o=w example.txt
    This is means apply read write and execute permissions to owner, and assign read and execute to group , and assign write permission to other.
owner ,No permissions to group and everyone example3.txt
    
     chmod u=rwx example3.txt
#-rwx——


    
   

chmod Examples:

chmod Examples Permissions Using Numeric mode :

Setting Read/Write/execute to owner Read/execute to group and everyone else to example1.txt
    
     chmod 755 example1.txt
#-rxwr-xr-x

    
   
Setting Read/Write to owner Read/execute to group and read only to everyone else to example2.txt
    
     chmod 664 example2.txt
#-rw-rw-r–

    
   
Setting Read/Write/execute to owner ,No permissions to group and everyone example3.txt
    
     chmod 700 example3.txt
#-rwx——

    
   

chmod Examples Permissions Using symbolic Permissions Notation :

Setting Read/Write/execute to owner Read/execute to group and everyone else to example1.txt
    
     chmod u=rwx,g=rx,o=rx example1.txt
#-rxwr-xr-x

    
   
Setting Read/Write to owner Read/execute to group and read only to everyone else to example2.txt
    
     chmod u=rw,g=rx,o=r example2.txt
#-rw-rw-r–

    
   
Setting Read/Write/execute to owner ,No permissions to group and everyone example3.txt
    
     chmod u=rwx example3.txt
#-rwx——

    
   
XsoftHost Support

Share

Recent Posts

Add Extra IP addresses to server configuration On Ubuntu 17.10 and later

Each failover IP address will need its own line in the configuration file. The configuration…

4 years ago

Create RAID Arrays with mdadm on Ubuntu

What is mdadm? The mdadm utility can be used to create and manage storage arrays…

4 years ago

How to change the maximum upload file size for PHP

There are several scenarios that you might need to increase or decrease your php maximum…

6 years ago

How to install Let’s Encrypt Plugin in WHM/cPanel

What is Let’s Encrypt? Let’s Encrypt is a free certificate authority provided by the Internet…

6 years ago

How to install python in my cPanel and add py extension

Python normally installed on all cPanel hosting server because most of Centos/red hat update system…

6 years ago

How to install and enable GUI GNOME Desktop on centos 7

Usually CentOS 7 comes in a numbers of variants, For most users, there are two…

6 years ago