Site icon LinuxCommands.site

linux chmod/chown syntax and chmod/chown examples

The previous article introduced linux file properties and permissions.

This article introduces the Linux Chmod command and chown command and their use.

linux chmod command

Chmod change file modes or Access Control Lists

Linux / Unix file call permission is divided into three levels: file owner, group and others.

Chmod can be used to control how files are called by others.

syntax

chmod [-fv] [-R [-H | -L | -P]] mode file ...

options

mode

The symbolic mode is described by the following grammar:

mode         ::= clause [, clause ...] 
clause       ::= [who ...] [action ...] 
action action       ::= op [perm ...] 
who          ::= a | u | g | o 
op           ::= + | - | = 
perm         ::= r | s | t | w | x | X | u | g | o

who

Reference   Class     Description
 u          owner      file's owner
 g          group      users who are members of
                       the file's group
 o          others     users who are neither the
                       file's owner nor members of 
                       the file's group
 a          all       All three of the above, same as ugo

perm

r       The read bits.
s       The set-user-ID-on-execution 
        and set-group-ID-on-execution bits.
t       The sticky bit.
w       The write bits.
x       The execute/search bits.
X       The execute/search bits if the file
        is a directory or any of the execute/search 
        bits are set in the original (unmodified) 
        mode. Operations with the perm symbol X'' 
        are only meaningful in conjunction with the 
        op symbol+'', and are ignored in all other cases.
u       The user permission bits in the original mode
        of the file.
g       The group permission bits in the original mode 
        of the file.
o       The other permission bits in the original mode 
        of the file.

op

Operator  Description
+         Adds the specified modes to the
          specified classes
-         Removes the specified modes from 
          the specified classes 
=         The modes specified are to be made
          the exact modes for the specified 
          classes

examples

$ sudo chmod ugo+x test 
➜ chmod 666 test 

Give all users access to read, write and execute files

➜ chmod 777 test

File owner read and write execution permission, readable by group and other users, execution permission

a is equivalent to “ugo”

User, group and other users read permissions.

official example

linux chown command

Chown change file owner and group.

This command can only be used by root.

syntax

chown [-fhnv] [-R [-H | -L | -P]] owner[:group] file ...

options

examples

$ sudo chown nobody test
$ sudo chown www-data:www-data test 

$ sudo chown -Rh root folder/

Recommended Posts:

Linux common commands tutorial and use examples
GNU sed syntax and sed examples
Awk tutorial: awk syntax and awk examples
linux iostat syntax and iostat examples
linux grep command and grep examples

Exit mobile version