Linux File basic attributes

Source: Internet
Author: User

Linux File basic attributes

Linux is a typical multi-user system. Different users are in different positions and have different permissions. To protect the security of the system, Linux requires different users to access the same file (including directory files.

In Linux, we can use the ll or ls-l command to display the attributes of a file and the users and groups to which the file belongs, such:

[root@www /]# ls -ltotal 64dr-xr-xr-x   2 root root 4096Dec142012 bindr-xr-xr-x   4 root root 4096Apr192012 boot……

In the instance, the first property of the binfile is represented by "d. "D" indicates that the file is a directory file in Linux.

In Linux, the first character indicates that the file is a directory, file, or link file.

  • When it is [D] Is the Directory
  • When it is [-] Is a file;
  • If [LLink file );
  • If [B] Indicates the interface device that can be stored in the device file (random access device );
  • If [C] Indicates the serial port device in the device file, such as the keyboard and mouse (one-time reading device ).

The following characters are a group of three parameters, all of which are a combination of the three parameters of "rwx. [R] indicates read, [w] indicates write, and [x] indicates execute ). Note that the positions of these three permissions will not change. If you do not have the permissions, the minus sign [-] will appear.

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

0-9 numbers are used from left to right.

0th-bit file type, 1-3-bit determine the owner of the file (the owner of the file) has the permission of the file.

The 4-6 digits determine that the group (the owner's users in the same group) has the permission to the file, and the 7-9 digits determine that other users have the permission to the file.

 

The 1st, 4, and 7 characters indicate the read permission. If the character "r" is used, the system has the read permission. If the character "-" is used, the system does not have the read permission;

2nd, 5, and 8 digits indicate the write permission. If the character "w" is used, the write permission is granted. If the character "-" is used, the write permission is not granted; 3rd, 6, and 9 Characters indicate the executable permission. If the character "x" is used, the execution permission is granted. If the character "-" is used, the execution permission is not granted.

Linux File owner and group
[root@www /]# ls -ltotal 64dr-xr-xr-x   2 root root 4096Dec142012 bindr-xr-xr-x   4 root root 4096Apr192012 boot……

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

In Linux, users are classified by group. 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, Linux requires different file access permissions based on the file owner, the file owner, the same group of users, and other users.

In the preceding example, the binfile is a directory file. Both the owner and the Group are root. The owner has the readable, writable, and executable permissions; other users in the same group as the owner have the readable and executable permissions. Other users also have the readable and executable permissions.

Change file properties 1. chgrp: change file group

Syntax:

Chgrp [-R] group name file name

Parameter options

  • -R: recursively change the file group. If the-R parameter is added to the group of a directory file, the group of all files in the directory will be changed.
2. chown: Change the file owner or change the file group.

Syntax:

Chown [-R] owner name file name chown [-R] owner name: group name file name

Enter the/root directory (~) 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 68495Jun2508:53 install.log

Change the owner and group of install. log to root:

[root@www ~]# chown root:root install.log[root@www ~]# ls -l-rw-r--r--1 root root 68495Jun2508:53 install.log
3. chmod: Change the nine attributes of the file.

Linux file attributes can be set in two ways: numbers and symbols.

There are nine basic permissions for Linux Files: owner, group, and others. Each of these three identities has its own read, write, and execute permissions.

First, review the data mentioned above: the File Permission character is "-rwxrwxrwx". The nine permissions are in three or three groups! Here, we can use numbers to represent each permission. The score of each permission is as follows:

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

The three permissions (r/w/x) of each identity (owner/group/others) must 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 change the permission settings, the permission number for this file is 770! The command chmod syntax for permission change is as follows:

Chmod [-R] xyz file or directory

Options and parameters:

  • Xyz: The permission attribute of the numeric type just mentioned. It is the sum of the values of the rwx attribute.
  • -R: Perform recursive changes, that is, all files under the directory will be changed together.

For example, to enable all the permissions of the. bashrc file, run the following command:

[root@www ~]# ls -al .bashrc-rw-r--r--1 root root 395Jul411:45.bashrc[root@www ~]# chmod 777.bashrc[root@www ~]# ls -al .bashrc-rwxrwxrwx  1 root root 395Jul411:45.bashrc

If you want to change the permission-Rwxr-xr --What about it? Then the permission score is [4 + 2 + 1] [4 + 0 + 1] [4 + 0 + 0] = 754.

Change file permissions by symbol type

There is another way to change permissions! From the previous introduction, we can find that the nine permissions are (1) user (2) group (3) others! Then we can use u, g, o to represent the permissions of three identities!

In addition, a represents all, that is, all identities! Then the read and write permissions can be written as r, w, x! That is to say, you can use the following method:

 

Chmod U
G
O
A
+ (Join)
-()
= (SET)
R
W
X
File or directory

If you need to set the File Permission to-rwxr-xr --, you can useChmod u = rwx, g = rx, o = r file nameTo set:

[root@www ~]# ls -al .bashrc-rwxr-xr-x  1 root root 395Jul411:45.bashrc[root@www ~]# chmod  a+w  .bashrc[root@www ~]# ls -al .bashrc-rwxrwxrwx  1 root root 395Jul411:45.bashrc

What if you want to remove the permission without changing other existing permissions? For example, to remove the executable permissions of all users:

[root@www ~]# chmod  a-x  .bashrc[root@www ~]# ls -al .bashrc-rw-rw-rw-1 root root 395Jul411:45.bashrc

This article permanently updates the link address:

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.