In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you the Linux Chinese file attributes, owners, groups, permissions of the example analysis, I believe that most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Write at the front
We all know that Linux is a system that supports multi-user and multi-task, which is also its best feature, that is, there may be many people working on the system at the same time, so do not force the shutdown. At the same time, in order to protect everyone's privacy and working environment, the Linux system defines three identities for a certain document (file, directory), namely, the owner (owner), the group (group), and others (others). Each identity corresponds to three kinds of permissions, namely, readable, writable and excutable. Through this design, the confidentiality of the data owned by each user can be guaranteed.
Document properties
Use the command ls-al-- full-time, or the abbreviated ll of this command, to view all the properties of a file or directory. As follows:
As you can see from the above, each row has seven columns, which are:
First column
A total of 10 bits, the first bit represents the document type, d represents the directory,-represents the file, l represents the linked file, d represents the random access device, such as U disk, etc., c represents the one-time reading device, such as mouse, keyboard, etc. The last 9 bits correspond to the permissions owned by the three identities, in the order of owner, group and others, and the order of permissions is readable, writable and excutable. For example, the meaning of the current document is that the current document is a file, the owner can read and execute, and the users in the same group can read and write, and others do not have any rights.
Second column
Represents the number of links
The third column
Represents the owner.
Fourth column
Indicates the group to which it belongs
Fifth column
Represents the size of the document in bytes
Sixth column
Indicates the last modification time of the document. Note that it is not the creation time of the document.
Seventh column
Represents the document name. To point (.) It starts with hiding the document.
Change owner (owner)
Position
Etc/passwd
Note: it must be an account that already exists in this location. That is, only the owner with a record in / etc/passwd can change.
Grammar
Chown [- R] [account name] [file or directory]
Chown [- R] [account name]: [group name] [file or directory]
Note: this command can also change the document group by the way, but it is recommended to use the chgrp command to change the document group.
Option
-R recursive change, that is, all files (folders) in the subdirectory will be changed.
Usage
Chown daemon test changes the folder test account number to daemon.
Chown daemon:root test changes the folder test group to root.
Chown root.users test changes folder account to root and group to users
Chown .root test changes the group to root separately
Note: although it is possible to add a decimal point (.) between the owner and the group, in order to avoid the naming of some students, it is recommended to use the colon ":" to separate the owner from the group to avoid misjudgment.
Change Group (group)
Position
Etc/group
Note: you can view all groups from here.
Grammar
Chgrp [- options] [group name] [document path]
Note: for options, you can query the detailed usage through man chgrp, info chgrp, chgrp-- help and other commands.
Usage
Chgrp-R users test changes the group of test folder and all its child files (folders) to users.
Note: if the group name is not in the location, an error invalid group will be reported.
Change of authority
There are only three basic permissions for Linux documents, namely read/write/execute, and there are only nine identity owner/group/others. There are two ways to change permissions, which are symbolic method and digital method.
Symbolic method
Three identities are represented by uther gmeno, a for all identities, r, w and x for three kinds of permissions, and +, -, and = for operation behavior respectively.
Grammar
Chmod | u g o a | + (join)-(remove) = (set) | r w x | document path
Set permissions (=)
Change the permissions of the directory test so that anyone can read, write, and execute.
Chmod uprirwx test gendarwx
Or
Chmod ugo=rwx test
Or
Chmod a=rwx test
Remove permissions (-)
Remove the directory test execution permission
Chmod UmurxMagi gripxmae o ripx test
Or
Chmod ugo-x test
Or
Chmod Amurx test
Note: execute permission (x), just to the directory is whether other users can cd test to become the working directory.
Add permissions (+)
Increase directory test execution permissions
Chmod upright, gourmet, and test.
Or
Chmod ugo+x test
Or
Chmod axix test
Note: familiar with it, if we finish writing a shell file test.sh, we add file execution permissions through chmod adepx test.sh.
Digital method
As the name implies, numbers are used to represent permissions. Rrecoery wpencil x is 4meme2pr 1 respectively. The permission of an identity can be obtained by adding up the three kinds of permissions.
Set the permissions of the directory test so that anyone can read, write and execute.
Chmod 777 test
Set the permissions of the directory test so that anyone can read and write.
Chmod 666 test
Give a shell file test.sh executable permission, the owner can read, write, execute, group accounts and others can read and execute.
Chmod 755 test
Note: have you found that the numerical method is simpler!
Differences in file and directory permissions
Document permissions vary greatly between files and directories
File
For the contents of the file
Readable can read the actual contents of the file
Writable can edit, add, or modify the contents of the file
Executable has permissions that can be executed by the system
Note: having w permission does not mean that files can be deleted. Deleting files is within the scope of directory permission control. That's because the relevant permissions and attributes of the directory are recorded to the inode of the directory, and the names of all files under the directory and the corresponding index file (inode) numbers are recorded in the block to which the directory belongs, so when we read a file, we must first read the inode of the directory, and then read the block information of the directory, and get the index information of the file to be read, that is, which block it is stored in. Finally, you can read the contents of the file (you need to understand Linux's file system, such as Ext2/Ext3/Ext4, which we will describe in more detail later)-keep in mind that file permissions are only valid for the contents of the file.
Example illustration
Use root identity to read the file test001-1 under the directory test001
View the full physical path of the directory: pwd
List the relevant directories and files: ll-di / / root/ root/test001/ root/test001/test001-1
Check-I via man ls, full name inode, that is, print the index number of each file
Inode of directory /: find the block with inode number 2 through the information of the mount point.
Block of directory /: through the block found in the previous step, the inode number of the root/ directory is 131073.
Inode of the directory root/: read the inode number 131073 to find the block of the directory.
Block of directory root/: through the block found in the previous step, find that the inode number of the root/test001/ directory is 527524.
Inode of the directory root/test001/: read the inode number 527524 to find the block of the directory.
Block of the directory root/test001/: through the block found in the previous step, find the file test001-1 directory with the inode number 527526.
Inode of file test001-1: read the inode number 527526 to find the block of the file.
Block of file test001-1: read the contents of the file through the block found in the previous step.
Because you are using the root identity, you have permission to read any document. If you use a general account, the read of each step above will also match the permissions.
Catalogue
For the file objects in this directory
Readable has permission to read the directory structure list, that is, you can query the directory list through the ls command.
Writable has the right to change the directory structure list, that is, you can create, migrate, delete, and rename files in this directory.
Executable has permission to enter this directory, that is, it can become a working directory through the cd command.
Note: as can be seen from the above, when opening the directory to anyone to browse, at least r or x permissions are required. To read the contents of a directory file, you need at least directory permissions x and file permissions r.
The above is all the contents of the article "sample Analysis of Linux document attributes, owners, groups, permissions". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow 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: 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.