content
Subscribe Quiz

CHMOD COMMANDS WITH EXAMPLES

by KAUSTUBH SHARMA on Feb. 16, 2022, 3:32 p.m. with 3228 views

CHMOD (change mode)

  • Linux/Unix command
  • Changes permissions of each file according to mode, where mode describes permissions to modify. The mode can be specified with NUMERIC MODE or LETTER MODE.

 

LETTER MODE:

Tag 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

NUMERIC MODE:

In numeric mode, we use one to four octal digits (0-7), derived by adding up the bits with values 4(22), 2(21), and 1(20).

where

  • "4" represents read permission
  • "2" represents write permission
  • "1" represents execution permission
  • The first digit represents owner permissions
  • The second digit represents group permissions
  • The third digit represents everyone's permissions

 

EXAMPLES

Read permission to owner only

$ chmod 400 test.yaml 

Read permission to group only

$ chmod 040 test.yaml 

Read permission to everyone

$ chmod 004 test.yaml 

Write permission to owner only

$ chmod 200 test.yaml 

Write permission to group only

$ chmod 020 test.yaml 

Write permission to everyone

$ chmod 002 test.yaml 

Execute permission to owner only

$ chmod 100 test.yaml 

Execute permission to group only

$ chmod 010 test.yaml 

Execute permission to everyone

$ chmod 001 test.yaml 

Allow owner and group and everyone with reading permission

$ chmod 444 test.yaml

Allow everyone to read, write, and execute the below file.

$ chmod 777 test.yaml

Learn more this through Video on -YouTube