Linux Command - chmod

chmod - change file mode bits.

It is very important you understand the Linux file permissions before changing mode bits.

Syntax

1
2
chmod [OPTION] MODE FILE
chmod [OPTION] OCTAL-MODE FILE

You can use symbolic mode here

1
[ugoa...][[+-=][perms...]...]

here

  • u = user
  • g = group
  • o = other
  • a = all

Options

option description
-R, –recursive change files and directories recursively
–reference=RFILE use RFILE’s mode instead of MODE values
-v, –verbose verbose mode

Example

Add execute permission to owner

1
chmod u+x file1

Remove execute permission from owner

1
chmod u-x file1

Add write permission for all

1
chmod a+w file1

Set owner’s permission to be execute only

1
chmod u=x file1

Set permission for owner, group

users has read,write, execute permission, group has read write permission, others

1
chmod u=rwx,g=rw file1

Remove write permission from owner for a directory

add -R option for change files and directories recursively

1
chmod -R u-w dir

Set permission using octal digits

set read permission only for all

1
chmod 444 file1

set read,write permission for owner and read permission for group

1
chmod 640 file1

Reference