Linux Basic Command (a) linux chmod command

Source: Internet
Author: User
Tags chmod numeric readable

The chmod command is used to change access rights for Linux system files or directories. Use it to control the access rights of files or directories. There are two ways to use this command. One is the text-setting method that contains the letters and operator expressions, and the other is the numeric setting that contains the numbers.

Each file and directory in a Linux system has access permission to determine who can access and manipulate files and directories in any way.

File or directory access is divided into read-only, write-only and executable three kinds. In the case of a file, read-only permission means that only its contents are allowed, and no changes to it are prohibited. Executable permission indicates that the file is allowed to be executed as a program. When a file is created, the file owner automatically has read, write, and execute permissions on the file to facilitate reading and modifying the file. Users can also set access permissions to any combination they need, as needed.

There are three different types of users who can access files or directories: The file owner, the same group of users, and other users. The owner is generally the creator of the file. The owner can allow the same group of users to have access to the file, and to give the file access to other users on the system. In this case, each user in the system has access to the files or directories owned by the user.

Each file or directory has three sets of access rights, each with three-bit representation, read, write, and execute permissions for the owner of the file, as well as read, write, and execute permissions for users of the same group, read, write, and execute permissions for other users in the system. When you use the LS-L command to display the details of a file or directory, the leftmost column is the file's access rights. For example:

Command:

Ls-al

Output:

[Root@localhost test]# Ll-al

Total 316lrwxrwxrwx 1 root 11-22 06:58 Linklog.log-> Log2012.log

-rw-r--r--1 root root 302108 11-13 06:03 log2012.log

-rw-r--r--1 root 11-13 06:03 log2013.log

-rw-r--r--1 root 0 11-13 06:03 log2014.log

-rw-r--r--1 root 0 11-13 06:06 log2015.log

-rw-r--r--1 root 0 11-16 14:41 log2016.log

-rw-r--r--1 root 0 11-16 14:43 log2017.log

We take Log2012.log as an example:

-rw-r--r--1 root root 296K 11-13 06:03 log2012.log

There are 10 positions in the first column, and the first character specifies the file type. In the usual sense, a directory is also a file. If the first character is a horizontal line, it represents a file that is not a directory. If it is D, the representation is a directory. From the second character to the tenth a total of 9 characters, 3 characters a group, respectively, representing 3 groups of users of the file or directory permissions. Permission characters use horizontal lines to represent a null license, R for read-only, W for write, and X for executable.

For example:

-rw-r--r--

Indicates that the log2012.log is a common file; the owner of the Log2012.log has read and write access, and the user with the Log2012.log is the only read access, and the other user has Read permission only.

After determining the access rights for a file, users can use the chmod commands provided by the Linux system to reset different access rights. You can also use the Chown command to change the owner of a file or directory. Use the CHGRP command to change the user group for a file or directory.

The chmod command is important to change the access rights of a file or directory. Users use it to control access to files or directories. Details of the chmod command are as follows.

1. Command format:

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

2. Command function:

Used to change the access rights of a file or directory, and use it to control access to files or directories.

3. Command parameters:

Necessary parameters:

-C Report processing information when a change occurs

-F error message does not output

-R handles all files in the specified directory and its subdirectories

-V Runtime displays detailed processing information

Select parameters:

--reference=< directory or File > set to have the same permissions as the specified directory or file

--version Display version Information

< permission range >+< permission settings > Make permission-scoped directories or files have the specified permissions

< permission range >-< permission setting > Delete permission range directory or file specified permissions

< permission range >=< permission settings > Set permissions for a directory or file that is a specified value

Permission range:

U: Current user of the directory or file

G: Current group of directories or files

O: Users or groups other than the current user or group of directories or files

A: All Users and Groups

Permission code:

R: Read permission, expressed in number 4

W: Write permission, expressed in number 2

X: Execute permissions, represented by the number 1

-: Delete permission, expressed in number 0

S: Special Permissions

There are two ways to use this command. One is the text-setting method that contains the letters and operator expressions, and the other is the numeric setting that contains the numbers.

1). Text Setting Method:

chmod [who] [+ | - | =] [mode] File name

2). Digital Setting method

We must first understand the meaning of a number-represented attribute: 0 means no permission, 1 for executable, 2 for writable, 4 for readable, and then adds. Therefore, the format of the numeric attribute should be 3 octal from 0 to 7, in the Order of (U) (g) (O).

For example, if you want the owner of a file to have read/write two permissions, you need to have 4 (readable) +2 (writable) =6 (read/write).

The general form of the digital setting method is:

chmod [mode] filename

Numbers correspond to characters as follows:

R=4,w=2,x=1

To rwx the property 4+2+1=7

To rw-the property is 4+2=6;

To r-x the property is 4+1=7.

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.