Linux chmod Command Detailed

Source: Internet
Author: User
Tags chmod readable file permissions

One, Linux under the directory and file permissions differences

File: Read file contents (r), write data to File (w), execute file As command (x).

Directory: Read the file name (R) contained in the directory, write the message to the directory (add and delete the link to the index point), search the directory (can use the directory name as the pathname to access the files and subdirectories it contains)


Specifically, that is:

(1) CD into the directory, ls list directory: read-only + Execute permissions

(2) The file under the directory: Users who have execute permission only when they know the file name and have read rights

(3) With write permission to the directory, you can create, delete, or modify any file or subdirectory under the directory, even if the file or subdirectory belongs to another user.


Second, Linux chmod command detailed

chmod command: Used to change the access rights of a file or directory. Users use it to control access to files or directories.

This command is 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.

1. Text Setting method

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

The meanings of the options in the command are:

Action object who is either or a combination of the following letters:

U means "user", which is the owner of the file or directory.

G means "same group user", that is, all users who have the same group ID as the file owner.

O means "other (others) users".

A means "all users". It is the system default value.


The operation symbols can be:

+ Add a permission.

-Cancels a permission.

= gives the given permission and cancels all other permissions, if any.

Setting the permissions represented by mode can be any combination of the following letters:

R is readable.

W writable.

X executable.

x append the x attribute only if the destination file is executable to some users, or if the target file is a directory.

S is the owner of the file in which the owner or group ID of the process is placed when the file is executed. The way "U+s" sets the user ID bit of the file, "G+s" sets the group ID bit.

T save the program's text to the swap device.

You have the same permissions as the owner of the file.

G has the same permissions as a user with the same group as the file owner.

o have the same permissions as other users.

File name: A list of files separated by spaces to change permissions, and wildcard characters are supported.

Multiple permission methods can be given in one command line, separated by commas. Example: chmod g+r,o+r Example

Enables the same group and other users to have read access to the file example.


2. Digital Setting method

The meaning of the attribute represented by the number: 0 means no permissions, 1 means executable permission, 2 is writable, 4 is read, and then it is added. So the format of the numeric attribute should be 3 octal numbers 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] file name


Example:

(1) Text setting method:


Example 1:$ chmod a+x sort

The properties of the set file sort are:

File owner (u) Increased execution permissions

Increase execution rights with the owner of the file in the same group as the user (g)

Additional users (O) Increased execution permissions


Example 2:$ chmod ug+w,o-x text

The property of the set file text is:

File owner (u) Add Write permission

Add write permissions to the same group of users as the file owner (g)

Other users (O) Remove Execute permissions


Example 3:$ chmod u+s a.out

Assume that the permissions for a.out after executing chmod are (can be seen with the Ls–l a.out command):

–rws--x--x 1 inin users 7192 Nov 4 14:22 a.out

And this execution file to use a text file shiyan1.c, its file access permission is "–RW-------", that is, the file only its owner has read and write permissions.


When other users execute a.out this program, his identity is temporarily inin because of this program (because the chmod command uses the S option), so he can read shiyan1.c this file (although this file is set to other people do not have any permissions), this is the function of S.

Therefore, in the whole system, especially the root itself, it is best not to set too much of this type of file (unless necessary) to ensure the security of the system, to avoid the bug of some programs to make the system compromised.


Example 4:$ chmod a–x mm.txt

$ chmod–x Mm.txt

$ chmod ugo–x Mm.txt

All of the above three commands delete the execution permission of the file Mm.txt, and it sets the object to be all the users.


(2) Digital setting Method:


Example 1: $ chmod 644 Mm.txt

$ ls–l

The properties of the set file Mm.txt are:

-rw-r--r--1 Inin users 1155 Nov 5 11:22 Mm.txt

File owner (U) inin has read and write permissions

User with file owner (g) has Read access

Other people (O) have read access


Example 2: $ chmod wch.txt

$ ls–l

-rwxr-x---1 inin users 44137 Nov 9:22 wchtxt

That is, set wchtxt the properties of this file are:

File owner (U) inin readable/writable/executable rights

(g) readable/enforceable rights with the main group of files

Other people (O) do not have any permissions

Original

Linux chmod Command Detailed

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.