In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How do I use the chmod command to change file permissions in Linux? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Linux's chmod command is used to change file permissions. There are three common permissions for files or directories, which are:
R: read
W: write
X: execute.
Today, I would like to introduce the meaning and usage of chmod command in detail.
The chmod command changes file permissions
I. symbolic mode
Command format:
Chmod [who] operator [permission] filename
The options contained in who and their implications:
U file belongs to the primary permission.
G belongs to group user rights.
O other user rights.
An all users (file owners, group users and other users).
The options contained in operator and their implications:
Increase permissions.
Revoke permissions.
Set permissions.
The options contained in permission and their implications:
R read permission.
W write permission.
X execute permissions.
S file owner and group set-ID.
T viscous bit *.
L locks the file to make it inaccessible to other users.
Operations for file owners, group users, and other users.
Filename is the file name of the file you want to operate on.
* the "t" bit is sometimes encountered when listing files or directories. "t" represents the sticky bit. If the "t" bit appears on a directory, this means that files in that directory can only be deleted by their owners, even if a subordinate group user has the same permissions as the owner. 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 (virtual memory) when it is executed.
Further explanation of "t" permission
1. T permission is an adhesive bit
Ex.: under the TMP directory, anyone has read and write permissions, but not anyone can delete files with writeable permissions inside. Of course not. This is the use of adhesive bits. Only the owner has the right to delete his own files, except for ROOT.
2. Another kind of permissions about file security, that is, unmodifiable permissions.
Example: chattr Usingi aaa, then the aaa file can not be modified, no matter anyone, if you delete it, you can use UMUI. A permission means only append permissions, which is very useful for logging systems. This permission allows the target file to be appended, not deleted, and not appended through the editor. Method is the same as I permission
If you want to see whether a file has this permission, just use lsattr filename
Example of changing permissions (temp is a file):
Chmod Amurx temp / / rw- rw- rw- withdraws execution permissions of all users chmod og-w temp / / rw- rMui-RMY-withdraws write permissions of group users and other users chmod Groupw temp / / rw- rw- RMI-gives write permissions to group users chmod Usingx temp / / rwx rw- Rafe-gives file owner execution rights chmod go+x temp / / rwx rwx r-x grants execution rights to group users and other users
2. Absolute mode
Command format
Chmod [mode] file
Where mode is an octal number, and each permission is represented by an octal number.
For example:
0400 files are readable to the master
02000 file is writable by owner
0 100 file owner executable
0 040 belongs to group user readable
0 020 belongs to group users can write
0 0 1 0 belongs to group user executable
0 004 readable by other users
0 002 other users can write
0001 other users can execute
When setting permissions, you only need to find out the numbers corresponding to the permissions of file owners, affiliated group users and other users according to the above, and add them up to represent the corresponding permissions.
For example, the symbolic mode permissions for the temp file are found to be:
-rwxr--r-- 1 wjr root 0 2008-09-21 16:40 temp
The first "-" indicates that the file is a general file.
Then, the corresponding absolute mode permission conversion process is:
Rwx:0400 + 0200 + 0100 (file owner can read, write, execute) = 0 70 0r--:0 040 (group user readable) = 0 04 0r--:0 040 (group user readable) = 00 400 7 4 4
It can also be calculated as follows:
The corresponding octal value is as follows. Add this value if you have the corresponding permission, or zero if you don't have it.
File owner: r w xRV 4 + 2 + 1
Group users: r w xRU 4 + 2 + 1
Other users: r w x RV 4 + 2 + 1
The permissions for the temp file are:
R w x r-- r-- 4 / 2 / 1 / 4 / 4
If you add up the corresponding permissions, it's 744.
As you can see, the maximum permission value that file owners, group users, and other users can have is 7.
Commands that change permissions such as:
$chmod 744 temp$ls-l temp
Results:
-rwxr--r-- 1 wjr root 0 2008-09-21 16:40 temp
Command:
$chmod 766 temp$ls-l temp
Results:
-rwxrw-rw- 1 wjr root 0 2008-09-21 16:40 temp
You can also set it with the files in the subdirectory by using the-R option:
$chmod-R 664 / temp/*
In this way, the permissions of all files in the / temp directory, together with files in each subdirectory, can be set to read and write by file owners and group users, and read-only by other users.
The-R option must be used with caution, only if you need to change the permissions of all files under the directory tree.
What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
After reading the above, do you know how to use the chmod command to change file permissions in Linux? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.