Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the common command chmod in Linux

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to use the Linux command chmod. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

Linux common command chmod (English spelling: change mode) command is to control the user's permissions on the file command, Linux/Unix file call permissions are divided into three levels: file owner (Owner), user group (Group), other users (Other Users).

syntax chmod [-cfvR] [--help] [--version] mode file... Parameter description mode : permission setting string, format:

[ugoa...] [[+-=][rwxX]...] [,...] Of which:

u denotes the owner of the file, g denotes a person who belongs to the same group as the owner of the file, o denotes someone other than the owner, and a denotes all three.

+ means to add permission, -means to cancel permission,= means to set only permission.

r means readable, w means writable, x means executable, and X means executable only if the file is a subdirectory or if the file has been set to executable.

Other parameters:

-c : If the file permissions have indeed changed, the change action will be displayed

-f : Do not display error messages if permissions on this file cannot be changed

-v : Display details of permission changes

-R : Make the same permissions change for all files and subdirectories in the current directory (i.e., change them recursively)

- help : Show help

- version : Display version

Symbolic mode uses symbolic mode to set multiple items: who (user type), operator (operator), and permission (permission), and the settings for each item can be separated by commas. The command chmod modifies the file access rights of the user type specified by who, which is specified by one or more letters in the position of who, as shown in the symbol pattern table of who:

who user type description uuser file owner ggroup file owner group others all other users aall users used, equivalent to ucooperatorsymbol pattern table:

Operator Description + Add permissions for specified user type-Remove permissions for specified user type = Set settings for specified user permissions, i.e. reset all permissions for user type Symbol pattern table for permission:

mode name description r read set to readable w write set to writable x execute set to executable x special execute set file permissions executable ssetuid/gid only when file is directory file or other types of user have executable permissions when file is executed, set setuid or setgid permissions of file according to user type specified by who parameter t paste bit set paste bit, only super user can set this bit, Only the file owner u can use this bit octal syntax The chmod command can use octal numbers to specify permissions. The permission bits of a file or directory are controlled by nine permission bits, each of which is a group of three bits, which are read, write, and execute by the file owner (User), read, write, and execute by the user group (Group), and read, write, and execute by other users (Other). Historically, file permissions have been placed in a bit mask where bits specified are set to 1 to indicate that a class has a corresponding priority.

#Permission rwx binary 7 read + write + execute rwx1116 read + write rw-1105 read + execute r-x1014 read-only r-1003 write + execute-wx0112 write-only-w-0101 execute only-x0010 none-000 For example, 765 would be interpreted as follows:

The owner's authority is expressed numerically: the sum of the numbers of the three authority bits belonging to the owner. For example, rwx, which is 4+2+1, should be 7.

The privileges of a user group are expressed numerically: the sum of the digits of that privilege digit belonging to the group. For example, rw-, which is 4+2+0, should be 6.

Digital representation of other users 'rights: the sum of the numbers of other users' rights bits. For example, r − x, which is 4+0+1, should be 5.

Example Make file1.txt readable by everyone:

chmod ugo+r file1.txt Make file1.txt accessible to all:

chmod a+r file1.txt Set file1.txt and file2.txt as the file owners, who belong to the same group can write, but others cannot write:

chmod ug+w,o-w file1.txt file2.txt Add executable permissions to ex1.py file owners:

chmod u+x ex1.py Make all files and subdirectories in the current directory readable by anyone:

chmod -R a+r * In addition, chmod can also be used to express permissions numerically, such as:

chmod 777 file syntax is:

chmod abc file where a,b,c are numbers representing User, Group, and Other permissions respectively.

r=4, w=2, x=1 If you want rwx attribute, then 4+2+1=7;

For rw-attributes 4+2=6;

For the r-x attribute 4+1=5.

chmod a=rwx file

chmod 777 file has the same effect

chmod ug=rwx,o=x file and

chmod 771 file has the same effect

Using chmod 4755 filename gives this program root privileges.

chmod a+r *file* increases read permissions for all users of file chmod a-x *file* deletes execution permissions for all users of file chmod a+rw *file* increases read and write permissions for all users of file chmod u=rw,go= *file* increases read and write execution permissions for all users of file chmod u=rw,go= *file* sets read and write permissions for the owner of file, clears all permissions of this user group and other users on file (spaces represent no permissions) chmod -R u+r, go-r *docs* adds read permissions to all files in the docs directory and its subdirectory hierarchy, and removes read permissions from user groups and other users chmod 664 *file* sets read and write permissions for file owners and user groups, and sets read permissions for other users chmod 0755 *file* is equivalent to u=rwx (4+2+1),go=rx (4+1 & 4+1). 0 There is no special pattern. chmod 4755 *file*4 sets the user ID bit, the rest is equivalent to u=rwx (4+2+1),go=rx (4+1 & 4+1). find path/ -type d -exec chmod a-x {} \; Remove executable permissions on path/and all its directories (excluding files) for all users, use '-type f' to match files find path/ -type d -exec chmod a+x {} \; Allow all users to browse or pass directories path/Thank you for reading! About "Linux common command chmod how to use" This article is shared here, I hope the above content can have some help for everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report