A summary of the rights related knowledge in some Linux shells

Source: Internet
Author: User
Tags chmod readable file permissions

This article mainly introduces some Linux shell in the relevant knowledge summary, so that the basics of Linux introductory learning, need friends can refer to the

Once a file is created, it has three ways to access it:

1) Read, you can display the contents of the file.

2) write, you can edit or delete it.

3 Execute if the file is an S H e l l script or program.

The permissions of a file can be grouped into three categories, according to the user being targeted:

1 The owner of the file, the user who created the file.

2 the same group of users, owns the file of the user group any user.

3 other users, that is, a user who does not belong to the user group that owns the file

The full information for the file includes the following:

The location of the file.

The file type.

File length.

Which user owns the file, and which users can access the file.

Node.

The time the file was modified.

The permission bits for the file.

You can view this information through ls-l, such as the following

?

1 2 3 4 5 6 7 [Root@ksharpdabu home]# ls-l total drwxr-xr-x 2 root 4096 Mar 10:00 bakblog-rwx------1 root root 786 Mar 15 10:18 backupblog.sh-rw-r--r--1 root 614 18:38 bk.sh drwx------2 www www 4096 Feb 17:04 www drwxr-xr-x 7 www www 4096 10:04 wwwroot

Total24: Represents the space occupied by all files in this directory

The preceding horizontal bar represents a normal file, and the following is a file type:

D directory.

L Symbolic Link (point to another file).

s socket file.

B Block device file.

C Character device file.

P Name the pipe file.

-Normal files, or more accurately, do not belong to several types of files.

-rw-r--r--: Indicates the relative permissions of the file, excluding the front bars, a total of nine characters,

Corresponds to 9 permissions, the first three characters represent the file owner, the middle three represents the same group of user rights, and the following three characters represent other user rights. Each person has three operations on a file

R Read permission

W Write/Change permissions

X permissions to execute this script or program

When a user creates a new file, the system, for security reasons, generally does not give the creator of the file permission to do so, that is, X. , for a file owner, a file redirection method can still be written to the file in the case where only the Read permission bit is placed. Note that the ability to delete a file also depends on the setting of the directory permission bit for that file. I personally think it is the intersection of the directory where the file resides and the permissions of the file itself.

The setting of the directory permission bit for the item. Some examples:

Meaning that the permission represents

R--------document is master readable but cannot be written or executed

r--r-----file is owned by the same group of users (typically the default group where the file owner is) readable

r--r--R-Text Any user can read, but cannot write or execute

RWX r--R-text file is mainly readable, written, executed, and the same group of users and other users can only read

RWX r-x---Document is mainly readable, written and executed, and can be read and executed by the same group of users.

RWX r-x r-x document is mainly readable, written, executed and readable and executed by the same group of users and other users.

rw-rw----Text files are both user-readable and writable by the same group

rw-rw-r--text files are user-readable and writable by the same group, and can be read by other users

rw-rw----Text file is the same group of users and other users read and write, and carefully use this permission settings, because any user can write to the file

To change the permissions of a file or directory, the following commands are commonly used, remember

The general format for the chmod command is:

chmod [who] operator [permission] filename

The meaning of W H o is:

U file is the primary permission.

G The same group of user rights.

o Other user rights.

A All users (file owner, same group user, and other user).

The meaning of O p e r a t o r:

+ Add permissions.

-Revoke permissions.

= Set permissions.

The meaning of P e R m i s i o N:

R Read permission.

W Write permission.

X Execute permissions.

s file is the owner and group S e t-i D.

t viscous bit *.

L LOCK the file so that other users cannot access it.

U,g,o actions for file owners, groups of users, and other users.

* the "T" bit is sometimes encountered when you are in a column file or directory. "T" represents a viscous bit. If the "T" bit appears on a directory, this means that the files in the directory can be deleted only by their owner, even if the same group of users has and the owner

The same permissions. However, some systems are not very strict in this rule.

If you see "T" in the file list, this means that the script or program will be placed in the swap area when executed (virtual

Deposit). But because today's memory prices are so low, you don't have to ignore the use of "T" files.

For example: Modify MyFile Permissions

Command result meaning

chmod a-x myfile rw-rw-rw-Reclaim all user's Execute permissions

chmod og-w myfile rw-r--R-Reclaim write permissions for same group of users and other users

chmod g+w myfile rw-rw-r--Give the same group of users write permissions

chmod u+x myfile rwx rw-r--Give file owner Execute permissions

chmod go+x myfile rwx rwx r-x give the same group of users and other users permission to execute

When we create the test file, it has the following permissions:

?

1 -rw-r--r--1 Dave Admin 614 Mar 16 18:38

I want to have permission to execute, and cancel all other users Read permissions, modify the following;

?

1 #chmod u+x o-r Test

The file permissions on test become

?

1 -RWXR-----1 Dave Admin 614 Mar 16 18:38

If you want a script file to be executable for yourself, and you're comfortable with the default permissions on the file, just make it executable for you.

?

1 # chmod U+x DT

Absolute mode of permission (that is, to use numbers to indicate permissions)

The general form of the chmod command absolute mode is:

?

1 chmod [mode] File

Where mode is a octal number. R is 4,w is 2,x is 1.

File owner of the same group of users other users

R W x R W x r W x

4 + 2 + 1 4 + 2 + 1 4 + 2 + 1

7 7 7

Modify test file as rwxr--r--

?

1 #chmod 744 Test

Modify Mydir Directory Extremely subdirectory permission is rwxr--r--

?

1 #chmod-R 744 Mydir//Where-R means recursion, which is to change all files in the Mydir directory, subdirectories to 744

Directory:

The directory has different permission bits and files. The Read permission bit for the directory means that the contents can be listed. Writing permission bits means that you can create files in the directory, and you can cancel the Write permission bit if you do not want other users to create files in your directory. Executing a permission bit means searching for and accessing the directory. If you set the same group of users or other users to-X for permissions on a directory, they will not be able to list the files in that directory. If the directory has a script or program that has a bit of execution location, it can still be executed as long as the user knows its path and file name. The user is not able to enter the directory without prejudice to his execution. The permissions for the directory will overwrite the permissions of the files in the directory. is to take their intersection

Note that the C h. O d command does not perform the necessary integrity checks and can give any permission to a worthless file, but

The chmod command does not perform any checks on the set of permission combinations. Therefore, do not see a file with Execute permissions,

Just think it must be a program or a script.

Suid and GUIDs are not introduced here, and can be made by Google Docs, or books

Chown: Modifying file owners

CHGRP: Modify all groups of files

The general form of the C H o w command is:

?

1 Chmod-r-H owner File

-The R option means the same thing is done for files in all subdirectories. -The H option means that changing the owner of a symbolic link file does not affect the destination file that the link points to.

CHGRP and Chown usage is similar, can own man

To view the commands of the group that you belong to:

?

1 #group或 #id

To see which group commands other users belong to:

?

1 #group User Name

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.