In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Xiaobian to share with you how to view file permissions under Linux, I believe most people do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
Every file or directory in linux contains access rights that determine who can access and how to access those files and directories.
I. View file permissions
First, at the terminal, you type this command.
ls -l
Get more detailed file information
img
Take mine as an example. We get eight columns of information, and we focus on file permission-related issues, so we leave out columns that are not file permission-related.
Column 1: File type and file permissions (this column consists of 11 characters, as follows)
The first character indicates the file type (such as the first character of the first character in the second column above), which is specifically: d: indicates a directory. -: This is an ordinary document. l: indicates that this is a symbolic link file, which actually points to another file. b, c: respectively represent block devices and other peripheral devices, is a special type of file. s, p: These files relate to the data structure and pipeline of the system and are usually rarely seen. File permissions: 9 characters from the second character to the last (2- 10th characters), three characters for a paragraph: such as rw-r--r--11th character: . Related to selinux, with this dot means selinux is on, without this dot means selinux is off (do not know)
So what do these nine permission bits from the second to tenth characters mean?
Review the concept of user and file permissions in Linux
user
Linux has two types of users: regular users and super (root) users.
Super user: can do anything under linux without restrictions
Regular users: do limited things under linux.
The command prompt at the terminal is "#" for super users and "$" for normal users.
The basic types of file permissions (there are some basic permissions do not explain) read (r): Read, for files, have the right to read the contents of the file; for directories, have the right to browse the directory information, note, for directories, browse means that, r permission only means that you have permission to know what content this directory will have, and does not mean that you can cd to the directory to work, this is x permission only. Write (w): Write, for files, permission to modify the contents of the file; for directories, permission to delete files in the move directory execute (x): execute, for files, permission to execute files; for directories, permission to enter the (cd) directory. In fact, for directories, if you only have x permission, without r permission, the ls command cannot be executed, because without r permission, the contents of this directory cannot be read.
and put them together as follows.
A few more concepts.
The creator of the file or the owner of the specified file
Belonging group: The group to which a file belongs (non-owner users within the group have permissions on the file)
Other: Other users who are neither owners nor members of a group
img
Each of these nine digits corresponds to the master, the group, and the others.
Put the above together and you have, for example,
rwx -----: The file owner has read, write, and execute permissions on the file. rwx r-- r--: The file owner has read, write, and execute permissions, while other users have read permissions. rw- rw- r-x: The file owner and the same group of users have read and write permissions on the file, while other users only have read and execute permissions. rwx --x --x: The directory owner has read, write, and access rights to the directory. Other users can access the directory, but cannot read any data. rwx -----: Users have no permissions at all on the directory except for the directory owner, who has full permissions.
Such combinations can also be converted into octal numbers by corresponding binary bits (i.e., the existence of the permission is 1, and the absence is 0).
img
II. Command related to file permissions
1)chgmod
Function: Set file access rights
Usage format: chgmod [parameter] permission file name
Common options: -R recursively change permissions on directory files
Its use format can be divided into two types
1. user identifier +/=/-permission character
img
For example:
Create a 123.txt file, check its file permissions, chmod command to increase its owner's executable permissions,
img
and then check their file permissions.
img
will find that its owner has enforceable rights.
2. three-digit octal number
for example
img
ps: It is important to note that only the owner and root of the file can change the permissions of the file.
2)chown
Function: Change the owner of a file
Format: chown [Parameter] User name File name
Common options: -R recursively change the owner of a file or directory file
For example:
The third and fourth columns of ps:ls -l are the file owner and group, respectively.
3)chgrp
Function: Change the group to which a file or directory belongs
Format: chgrp [Parameter] User group name File name
Common options: -R Recursively change the group to which a file or directory belongs
For example:
img4)umask
Function: View or modify file mask
What's the use of masks? Let's not complicate things, let's just say it's like this
Default permissions for new files = 0666-Mask permission values
Default permissions for new folders = 0777-Mask permission values
Format: umask mask permission value
Subtract the mask permission value from the user's existing file permissions to get the default permissions for the newly created file or folder. The default mask permission value is 0022 for super users and 0002 for normal users
For example:
img
It is recommended that you do not change the mask yourself, so as not to cause unnecessary trouble (for example, after someone changed it, every time you create a file, you have to manually add executable, and you can't remember changing the mask = = for a long time), like I changed it immediately after the test.
III. Viscous position
chmod +t folder name
This is actually very simple, don't make it complicated, what is the viscosity?
It's a special permission set for directories.
directories with sticky bits set can only be deleted by superuser, the directory, or the file owner
Note: Sticky bits can only be set for directories, and are invalid for file settings
The above is "How to view file permissions under Linux" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
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: 288
*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.