Latest web development tutorials

Linux chmod command

Linux chmod command

Linux command Daquan Linux command Daquan

File calls permissions Linux / Unix is ​​divided into three levels: the file owner, group, others. Use chmod can exercise control over how the file is called by others.

Access: All users

grammar

chmod [-cfvR] [--help] [--version] mode file...

Parameter Description

  • mode: permissions string in the following format:
    [ugoa...][[+-=][rwxX]...][,...]

    among them:
    • u represents the owner of the document, g represents the owner of the file belong to the same group (group) who, o that other people outside, a three represent both.
    • + Means increased authority - indicates remove permissions, = represent the only set permissions.
    • r represents read, w represents the write, x for executable, X represents only if the file is a subdirectory or the file has been set off as executable.
  • -c: If the file permissions have changed indeed, it shows the change action
  • -f: If the file permissions can not be changed and do not display an error message
  • Details Show Permissions changed: -v
  • -R: All the files and subdirectories under the current directory will be the same permission to change (that is handed back, one by one change)
  • --help: Display HELP
  • --version: display version
  • Examples

    Anyone can file file1.txt to read:

    chmod ugo+r file1.txt

    Anyone can file file1.txt to read:

    chmod a+r file1.txt

    The file file1.txt with file2.txt to the file owner, it belongs with a group who can write, but others outside of it can not be written:

    chmod ug+w,o-w file1.txt file2.txt

    Ex1.py will set only the file owner can execute:

    chmod u+x ex1.py

    The current directory of all the files and subdirectories are set anyone can read:

    chmod -R a+r *

    In addition chmod you can also use numbers to represent privileges such as:

    chmod 777 file

    The syntax is:

    chmod abc file

    Where a, b, c are each a number, respectively permissions User, Group, and Other's.

    r = 4, w = 2, x = 1

    • To rwx property is 4 + 2 + 1 = 7;
    • To rw- property is 4 + 2 = 6;
    • To rx property is 4 + 1 = 5.
    chmod a=rwx file

    and

    chmod 777 file

    The same effect

    chmod ug=rwx,o=x file

    and

    chmod 771 file

    The same effect

    If using chmod 4755 filename to make this program has root privileges

    Linux command Daquan Linux command Daquan