Linux File Basic Properties

Source: Internet
Author: User
Tags readable

Linux system is a typical multi-user system, different users in different positions, with different permissions. In order to protect the security of the system, the Linux system has different requirements for 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:

[[Email protected]/]#Ls-ltotal 64dr-xr-xr-x 24096 dec 14< Span class= "PLN" > 2012 Bindr-XR -xr-x 4  root root 4096 apr 19 2012 Boot ...      

instance, the first property of the bin file is represented by "D". "D" on Linux represents the file as a directory file.

The first character in Linux means that the file is a directory, a file, or a linked file, and so on.

    • When [ D ] is the directory
    • When [ - ] is the document;
    • If [ l ] is indicated as a linked document (link file);
    • If [ b ] is indicated as the device file inside the storage interface device (can be random access device);
    • If [ C ] is indicated as a serial port device inside the appliance file, such as a keyboard, mouse (one-time reading device).

In the following characters, a group of three, each of which is a combination of three parameters, is "rwx". where [R] stands for readable (read), [W] stands for writable (write), [x] stands for executable (execute). Note that the location of the three permissions does not change, and if there is no permission, a minus sign [-] is present.

The properties of each file are determined by the 10 characters of the first part of the left (for example).

0-9 of these numbers are used to indicate from left to right.

The No. 0 bit determines the file type, and 第1-3位 determines that the owner of the file owns the file's permissions.

第4-6位 determines that the owning group (the same group of users of the owner) has permission to the file, 第7-9位 determines the permissions that other users have on the file.

Where the 1th, 4, 7 is the Read permission, if the "R" character is indicated, then there is read permission, if the "-" character, there is no Read permission;

The 2nd, 5, 8 bits indicate write permissions, if the "W" character is indicated, there is write permission, if the "-" character indicates that there is no write permission, the 3rd, 6, 9 bits indicate the executable permission, if the "x" character is indicated, there is the execution permission, if the "-" character, there is no execute permission.

Linux file owner and owner group
[[Email protected]/]#Ls-ltotal 64drwxr-xr-x 2 root root 4096 feb 15  14:46 Crondrwxr-xr-x 34096 apr 21< Span class= "PLN" > 2014 Mysql ...       

For a file, it has a specific owner, that is, the user who owns the file.

At the same time, in a Linux system, users are categorized by group, and one 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 as the file owner.

Therefore, the Linux system sets different file access rights by file owner, file owner, and other users.

In the above example, the MySQL file is a directory file, both the master and the group are MySQL, the owner has a readable, writable, executable permissions, and other users of the same group are readable and executable permissions, and other users have readable and executable permissions.

For root users, the file's permissions generally do not work on it.

Change file properties 1, chgrp: Change file group

Grammar:

[-R] belongs to group name file   name

Parameter options

    • -R: Recursively change the group of files, that is, when you change the genus of a directory file, if you add the-r parameter, the group of all files under that directory will change.
2, Chown: Change the owner of the file, you can also change the file group

Grammar:

[-R] belongs to the main name file name [-R] belongs to the main  name:       The name of the group name 

Enter the/root directory (~) to change the owner of the Install.log to bin this account:

[[Email protected]~]Cd~[[email protected] ~]# Chown bin Install. Log[[email protected] ~]# ls -l-rw-r< Span class= "pun" >--r-- 1  bin users 68495 jun Span class= "lit" >25 08:53  Install.                 

Change the owner and group of the Install.log back to root:

[[Email protected]~]# chown root:root install.  Log[[email protected] ~]# ls -l-rw-R--R-- 1 root root 68495 June  : install.  Log                  
3, chmod: Change the file 9 properties

There are two ways to set up Linux file attributes, one is a number and one is a symbol.

Linux files have the basic permissions of nine, respectively, owner/group/others three identities each have their own Read/write/execute permissions.

First review the data just mentioned above: The file's permission character is: "-rwxrwxrwx", these nine permissions are three three a group! Where we can use numbers to represent individual permissions, the scores for each permission are as follows:

    • R:4
    • W:2
    • X:1

Each identity (Owner/group/others) 's respective three permission (R/W/X) scores are cumulative, such as when the permission is: [-rwxrwx---] score:

    • Owner = rwx = 4+2+1 = 7
    • Group = RWX = 4+2+1 = 7
    • others=---= 0+0+0 = 0

So wait a minute. When we set the permission change, the permission number of the file is 770! The syntax for the Change permission directive chmod is this:

[-R] file or directory  

Options and Parameters:

    • XYZ: is the permission attribute of the number type just mentioned, which is the sum of the numeric values of the Rwx property.
    • -R: Continuous change of recursion (recursive), i.e. all files in the secondary directory will be changed

For example, if you want to set all permissions for the. bashrc file to Enabled, the command is as follows:

[[Email protected]~]#Ls-Al.Bashrc-rw-R--R-- 1Root root395 Jul 4 11:45 bashrc[[email protected] ~]# chmod 777 .[[email protected] ~]# ls Span class= "pun" >-al .-rwxrwxrwx 1 root root 395 jul 4  11:45 BASHRC               

What if you want to turn permissions into -rwxr-xr-- ? Then the score of the privilege becomes [4+2+1][4+0+1][4+0+0]=754.

Symbol Type Change file permissions

There is also a way to change the permissions yo! From the previous introduction, we can find that basically nine permissions are (1) User (2) group (3) Others three kinds of identities! Then we can represent three kinds of identities by u, G, O!

In addition, a represents all and all identity! Then the permission to read and write can be written as R, W, x! That is, you can see it in the following way:

chmod U
G
O
A
+ (Join)
-(remove)
= (set)
R
W
X
File or directory

If we need to set the file permissions to -rwxr-xr-- , you can use the chmod u=rwx,g=rx,o=r file name to set:

# Touch Test1//Create Test1 file# Ls-al Test1//view test1 default permissions-rw-R--R-- 1 root root 0 nov 15 10:32< Span class= "PLN" > Test1# chmod u=rwx,g=rx,o=r test1//Modify Test1 Permissions  # ls-al test1-rwxr-< Span class= "PLN" >xr-- 1 root root 0 nov 15 Span class= "lit" >10:32 test1      

And if you want to remove permissions without changing other existing permissions? For example, to take out the executable permissions of all people:

#  chmod  a-x test1# ls-al test1-rw-R--R--10Nov  : test1             

Linux File Basic Properties

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.