One Linux command per day (chmod) command

Source: Internet
Author: User

The chmod command is used to change the permissions of a file or directory.

In the UNIX system family, the control of file or directory permissions is distinguished by reading, writing, performing 3 general permissions, and 3 special permissions are available for use. The user can use the chmod instruction to change the file and directory permissions, the format of the use of text or digital code can be. The permissions of the symbolic connection cannot be changed, and if the user modifies the permissions on the symbolic connection, the change will affect the original file being connected.

(1) Usage:

usage: chmod [Options] [mode] schema file

or chmod [-CFVR] [--help] [--version] Mode file

Commands are used in two ways: one is a text-setting method that contains letters and operator expressions, and the other is a digital setting method that contains numbers.

(2) Function:

function: used to change the access rights of a file or directory, using it to control access to a file or directory.

(3) Detailed parameters:

1)-r--recursive: Recursive processing, all files and subdirectories under the instruction directory are processed together

2)-v--verbose: Show instruction execution process

3)--reference=< reference file or directory;: Set all the groups of the specified file or directory to the same group as the reference file or directory

4) < permission range >+< permissions setting;: The option permission setting for a file or directory that has permission scope enabled

< permission range >-< permission setting;: Turn off permissions for files or directories that have permission settings

< permission scope >=< permission setting;: Specify permission settings for a file or directory for a range of permissions

(4) Representation of the scope of authority:
1) u user is the owner of the file or directory

2) G Group is the group that belongs to the file or directory

3) O Other users in addition to the file or directory owner or group belong to this scope

4) A all users, including owners, groups and other users

5) r Read permission, the number code is "4"

6) W Write permission, number code is "2"

7) x execute or switch permission, number code is "1"

8)-no permission, number code "0"

9) s special function Description: Change the permissions of a file or directory

(5) Example:

1) [[email protected] documents]# chmod a+x core.log Add executable permissions for all user groups

[email protected] documents]# LL-al core.log//ll-al file name and ls-l file name seem to be no different .-rw-r--r--.1Root root -May + Geneva: +core.log[[email protected] documents]# ls-L Core.log-rw-r--r--.1Root root -May + Geneva: +Core.log[[email protected] documents]# chmod a+x core.log [[email protected] documents]# ll-Al Core.log-rwxr-xr-x.1Root root -May + Geneva: +Core.log

2) [[email protected] documents]# chmod ug+w,o-x core.log Add or remove permissions for different users at the same time

[email protected] documents]# ll-al core.log1 May  :21  core.log[[email protected] documents]# chmod ug+w,o--l core.log127 May  : Core.log

3) [[email protected] documents]# chmod g=x,o=rwx core.log set three permissions for the u,g,o of the file. Here is the set file owner permission to be executable, other users can read and write execution, group user permissions are not changed

[email protected] documents]# ll-l core.log1 May  :21  core.log[[email protected] documents]# chmod g=x,o=-l core.log127 May  : Core.log

4) [[email protected] documents]# chmod-r o=---finddir recursive settings finddir folders under other user rights for files and folders without any permissions

[Email protected] documents]# Chmod-r o=---Finddir[[email protected] documents]# find.-name"Dir"-Print./Dir[[email protected] documents]# find.-name"Dir"-exec LS-l {} \; Total usage A--w-------.1Root root664May9  -: -Head_text--w-------.1Root root $May9  ,: theLess1--w-------.1Root root $May9  ,: -less2[[email protected] documents]# ls-l dir Total dosage A--w-------.1Root root664May9  -: -Head_text--w-------.1Root root $May9  ,: theLess1--w-------.1Root root $May9  ,: -Less2

5) [[email protected] documents]# chmod-r u=r,g=r,o=r finddir with [[email protected] documents]# chmod-r =rx Dir equivalently to UG o User-set permissions

[Email protected] documents]# chmod-r u=r,g=r,o=r finddir[[email protected] documents]# ls-l finddir Total dosage0-r--r--r--.1Root root0May - Geneva: -p1.pdf-r--r--r--.1Root root0May - Geneva: -p2.pdf-r--r--r--.1Root root0May - Geneva: -T1.txt-r--r--r--.1Root root0May - Geneva: GenevaT1.txt-r--r--r--.1Root root0May + Geneva: -T2.txt-r--r--r--.1Root root0May - Geneva: Genevat2.txt[[email protected] documents]# ls-l dir Total dosage A--w-------.1Root root664May9  -: -Head_text--w-------.1Root root $May9  ,: theLess1--w-------.1Root root $May9  ,: -Less2[[email protected] documents]# chmod-R =Rx Dir//Set all group user rights to RW after the previous owner's W permission is gone [[email protected] documents]# ls-l dir Total dosage A-r-xr-xr-x.1Root root664May9  -: -Head_text-r-xr-xr-x.1Root root $May9  ,: theLess1-r-xr-xr-x.1Root root $May9  ,: -Less2

6) [[email protected] documents]# chmod 444 find use numbers to set permissions on files

444-L find10 May  :
[[email protected] documents]# chmod =R newlocate                -l newlocate10 May   : newlocate

(6) Other:

Linux users are divided into: owners, groups, and others.

Linux system, in a preset situation, all the accounts in the system and general identity users, as well as root information, are recorded in the/etc/passwd file. Each person's password is recorded under the/etc/shadow file. In addition, all the group names are recorded in/etc/group!

One Linux command per day (chmod) command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.