In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the basic attributes of the Linux file, the content is clear, interested friends can learn, I believe that after reading it will be helpful.
Linux system is a typical multi-user system, different users are in different positions and have different permissions. In order to protect the security of the system, the Linux system makes different provisions on the permissions of different users to access the same file (including directory files).
In Linux, we can use the ll or ls-l command to display the properties of a file and the users and groups to which the file belongs, such as:
[root@www /] # ls-ltotal 64dr-xr-xr-x 2 root root 4096 Dec 14 2012 bindr-xr-xr-x 4 root root 4096 Apr 19 2012 boot.
In the example, the first attribute of the bin file is represented by "d". "d" means that the file is a directory file in Linux.
The first character in Linux indicates whether the file is a directory, a file, a linked file, and so on.
When it is [d], the directory is a file when it is [-]; if it is [l], it is expressed as a linked document (link file); if it is [b], it is expressed as an interface device available for storage in the device file (random access device); if it is [c], it is expressed as a serial port device in the device file, such as keyboard, mouse (one-time reading device). In the following characters, a combination of three parameters, all of which are "rwx". Where [r] represents readable (read), [w] represents writable (write), and [x] represents executable (execute). It is important to note that the location of these three permissions will not change, if there are no permissions, there will be a minus sign [-].
The attributes of each file are determined by the 10 characters in the first part on the left (see figure below).
It is represented by the numbers 0-9 from left to right.
Bit 0 determines the file type, and bits 1-3 determine that the owner (the owner of the file) has permissions for the file.
Bits 4-6 determine that the group (the same group user of the owner) has permissions for the file, and bits 7-9 determine that other users have permissions for the file.
Bits 1, 4 and 7 represent read permissions. If they are represented by "r" characters, they have read permissions, and if they are represented by "-" characters, they do not have read permissions.
Bits 2, 5, and 8 represent write permission, if represented by the "w" character, there is write permission, if the "-" character indicates that there is no write permission; bits 3, 6, and 9 indicate executable permission, and if represented by the "x" character, there is execution permission, and if it is represented by the "-" character, there is no execution permission.
Linux file owners and groups
[root@www /] # ls-ltotal 64drwxr-xr-x 2 root root 4096 Feb 15 14:46 crondrwxr-xr-x 3 mysql mysql 4096 Apr 21 2014 mysql.
For a file, it has a specific owner, that is, the user who has ownership of the file.
At the same time, in the Linux system, users are classified by groups, and a user belongs to one or more groups.
Users other than the file owner can be divided into the same group of users and other users of the file owner.
Therefore, the Linux system defines different file access permissions according to the file owner, the file owner, and other users.
In the above example, the mysql file is a directory file, and both the owner and the group are mysql, and the owner has read, write, and executable permissions; other users in the same group as the owner have read and executable permissions; and other users also have read and executable permissions.
For root users, the permissions of the file generally have no effect on them.
Change file properties
1. Chgrp: change the file belonging to the group
Syntax:
Chgrp [- R] group name file name
Parameter option
-R: recursively change the group of files, that is, when you change the group of a directory file, if you add the parameter of-R, then the group of all files in that directory will change.
2. Chown: change the file owner or change the file group at the same time
Syntax:
Chown [- R] generic host name file name
Chown [- R] generic name: generic group name file name
Enter the / root directory (~) and change the owner of install.log to the account bin:
[root@www] cd ~
[root@www ~] # chown bin install.log
[root@www ~] # ls-l
-rw-r--r-- 1 bin users 68495 Jun 25 08:53 install.log
Change the owner and group of install.log back to root:
[root@www ~] # chown root:root install.log
[root@www ~] # ls-l
-rw-r--r-- 1 root root 68495 Jun 25 08:53 install.log
3. Chmod: change 9 attributes of the file
There are two ways to set the properties of a Linux file, one is a number, the other is a symbol.
There are nine basic permissions for Linux files, and each of the three owner/group/others identities has its own read/write/execute permissions.
First review the data just mentioned: the permission character of the file is: "- rwxrwxrwx", these nine permissions are in groups of three! Among them, we can use numbers to represent each permission. The score comparison table of each permission is as follows:
R:4
W:2
X:1
The three r/w/x scores for each owner/group/others need to be accumulated, for example, when the permission is: [- rwxrwx---] the score is:
Owner = rwx = 4 "2" 1 = 7
Group = rwx = 4 "2" 1 = 7
Others=-= 0,0,0 = 0
So when we set the permission change later, the permission number of this file will be 770! The syntax for the directive chmod to change permissions is as follows:
Chmod [- R] xyz file or directory
Options and parameters:
Xyz: the permission attribute of the numeric type just mentioned, which is the sum of the values of the rwx attribute.
-R: make continuous recursive changes, that is, all files in the subdirectory will change.
For example, if you want to enable all permissions in the .bashrc file, the command is as follows:
[root@www ~] # ls-al .bashrc-rw-r--r-- 1 root root 395 Jul 4 11:45. Bashrc [root@www ~] # chmod 777. Bashrc [root@www ~] # ls-al. Bashrc-rwxrwxrwx 1 root root 395 Jul 4 11:45.
What if you want to change permissions to-rwxr-xr--? Then the score of the permission is [4-2-1] [4-0-1] [4-0-0] = 754.
Symbol type changes file permissions
There is another way to change permissions. From the previous introduction, we can find that there are basically nine permissions:
(1) user
(2) group
(3) others
Then we can use u, g, o to represent the permissions of the three identities!
In addition, a stands for all, that is, the full identity. Read and write permissions can be written as r, w, x, that is, you can use the following table to view:
If we need to set the file permissions to-rwxr-xr--, we can set it using the file name of chmod uplirwx journal gendrx journal oinitir:
# touch test1 / / create test1 file # ls-al test1 / / View test1 default permissions-rw-r--r-- 1 root root 0 Nov 15 10:32 test1# chmod upright rwx journal / test1 test1 / / modify test1 permissions # ls-al test1-rwxr-xr-- 1 root root 0 Nov 15 10:32 test1
And what if you want to remove permissions without changing other existing permissions? For example, to remove the executable permissions of all people, then:
# chmod Amurx test1
# ls-al test1
-rw-r--r-- 1 root root 0 Nov 15 10:32 test1
After reading the above content, do you have a further understanding of the basic properties of Linux documents? if you want to learn more, you are 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.