chmod 777 to modify permissions under Linux

一、rwxrwxrwx 777

In the Unix/Linux operating system, each file (folder is also regarded as a file) has permissions set according to read, write, and run. For example, when using ls -lthe command line file list, the following output is obtained:
-rw-r–r-- 1 mchopin users 2254 2006-05-20 13:47 uu.htm

  • Starting from the second character rw- means that the user mchopin has read and write permissions, but no execution permission.
  • The following r– indicates that the user group users has only read permission and no execution permission.
  • The last r-means that other people only have read permission, no write and run permission.

This is the default setting of the system, and uu.htm can be rewritten. People in the same group and other people only have the right to read it, and no one has the right to run it, because it is just an html file and does not need to be run. This is very advanced before Novell's directory services.
The three permissions of reading, writing, and running can be represented by numbers, that is r=4,w=2,x=1. rw-r--r--So, the numerical representation in the above example is 644.
Conversely, 777 is rwxrwxrwx, which means that the login user (you can use the command id to view) belongs to the group and other people have the highest authority.

chmod o-r uu.htmChange permissions, or subtract read from the permissions of others. The result is
-rw-r----- 1 bu users 2254 2006-05-20 13:47 uu.htm
If used chmod 777 uu.htm, the result is
-rwxrwxrwx 1 bu users 2254 2006-05-20 13:47 uu.htm
anyone All have read, write, run three permissions.

2. Command name: chmod

Access authority: All users
How to use: chmod [-cfvR] [–help] [–version] mode file...
Description: Linux/Unix file access permissions are divided into three levels: file owner, group, and others. Use chmod to control how files are accessed by others.

Parameter format:
mode: permission setting string, the format is as follows: [ugoa…][[±=][rwxX]…][,…], where

① u: indicates the owner of the file, g indicates the person who belongs to the same group as the owner of the file, o indicates someone other than others, and a indicates all three.
② +: Indicates to increase the authority, - indicates to cancel the authority, = indicates the only set authority.
③ r: means readable, w means writable, x means executable, X means only when the file is a subdirectory or the file has been set as executable. -c: Only display the change action if the file permission has been changed
④ -f: If the file permission cannot be changed, do not display an error message
⑤ -v: Display the detailed information of the permission change
⑥ -R: For the current directory All files and subdirectories of the same permission change (that is, change one by one in a recursive manner)
⑦ --help: display auxiliary instructions
⑧ --version: display version

3. Examples

r=4, w=2, x=1
If you want rwx attribute, then 4+2+1=7;
if you want rw- attribute, then 4+2=6;
if you want rx attribute, then 4+1=5.

①Set the file.txt to be readable by everyone chmod ugo+r file.txt
②Set the file.txt to be readable by everyone chmod a+r file.txt
③Set the file.txt and file2.txt as the owner of the file, and they belong to the same group Only the owner of the file can write, but others cannot. chmod ug+w,o-w file.txt file2.txt
④Set ex1.py so that only the owner of the file can execute chmod u+x ex1.py
⑤Set all files and subdirectories in the current directory to be readable by anyone chmod -R a+r *
⑥In addition chmod can also use numbers to indicate permissions eg chmod 777 file.
⑦ Grammar is chmod abc file. Among them, a, b, and c are each a number, respectively representing the permissions of User, Group, and Other.
chmod a=rwx fileis chmod 777 filethe same as the effect.
chmod ug=rwx,o=x filehas chmod 771 filethe same effect.
⑩If you use it, chmod 4755 filenameyou can make this program have root authority.

Guess you like

Origin blog.csdn.net/ChineseSoftware/article/details/128182457