Basic Attributes of Linux Files

Source: Internet
Author: User

Basic Attributes of Linux Files
Basic Attributes of Linux Files

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 4096 Dec 14  2012 bindr-xr-xr-x   4 root root 4096 Apr 19  2012 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.

If it is [d], it is a directory; if it is [-], it is a file; if it is [l], it is represented as a link file ); if it is [B], it indicates the interface device (random access device) in the device file; if it is [c], it indicates the serial port device in the device file, for example, 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. <喎? kf ware vc " target="_blank" class="keylink"> Examples/rXEy/examples + tcTIqM/eoaM8L3A + examples + samples + tcTIqM/eoaM8L3A + examples/ux7cq + o6zU8tPQtsHIqM/examples/eo7s8L3A + examples/ux7cq + examples/Examples/ ux7cq + logs/ux7cq + o6zU8sO709DWtNDQyKjP3qGjPC9wPg0KPGhyIC8 + DQo8aDIgaWQ9 "linux File owner and owner group"> Linux File owner and owner Group

[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 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 above example, the mysql file is a directory file, and its owner and group are both mysql. 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.

For root users, file permissions do not work normally.

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 68495 Jun 25 08: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 68495 Jun 25 08: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.

The permission character of the file mentioned above is "-rwxrwxrwx". These nine permissions are set by three or three! 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 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 .bashrc

What if I want to change the permission to-rwxr-xr? 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:

Command Owner name Operation Permission Target
Chmod U (user) + (Join) R (read) File or directory
  G (group) -() W (write)  
  O (others) = (SET) X (execution)  
  A (all)      

If we need to set the File Permission-Rwxr-xr-, You can use chmod u = rwx, g = rx, o = r file name to set:

# Touch test1 // create the test1 file # ls-al test1 // view test1 default permission-rw-r -- 1 root 0 Nov 15 test1 # chmod u = rwx, g = rx, o = r test1 // modify test1 permission # ls-al test1-rwxr-xr -- 1 root 0 Nov 15 test1

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

#  chmod  a-x test1# ls -al test1-rw-r--r-- 1 root root 0 Nov 15 10:32 test1

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.