After the command ls-l in Linux, what does the number behind the file type permission mean __linux

Source: Internet
Author: User
Tags parent directory

[Root@localhost ~]# Ls-l

Total 152

-rw-r--r--1 root root 2915 08-03 06:16 A

-RW-------1 root root 1086 07-29 18:35anaconda-ks.cfg

................................................

Line 1th: Total

The number after total is the sum of space occupied by all files in the current directory. Use LS–LH to view, or use Ls–alh to view

1th Field: File property field

-rw-r--r--1 root root 762 07-29 18:19 exit

The File property field has a total of 10 letters; The first character represents the file type.

-Indicates that the file is a normal file

D indicates that the file is a directory, the letter "D", is the abbreviation for the Dirtectory (directory)

Note: A directory or a special file that holds information about other files or directories

L indicates that the file is a linked file. The letter "L" is the abbreviation for link (link), similar to a shortcut under Windows

B's Representation block device files (blocks), generally placed in the/dev directory, device files are ordinary files and programs access to hardware devices, is a very special file. There is no file size, only one main device number and one auxiliary device number. A whole block of data transmitted at a time is called a block device, such as a hard disk, a CD-ROM, etc. The smallest data transmission unit is one block (usually a block size of 512 bytes)

c indicates that the file is a character device file (character), generally placed in the/dev directory, one byte transmission of the device is called a character device, such as keyboard, character terminal, etc., the smallest unit of transmission data is a byte

P indicates that the file is a command pipe file. Files related to Shell programming

s indicates that the file is a sock file. Files related to Shell programming

Link files are either hard links or symbolic links.

Hard links: Multiple points to the same file. The hard link file is exactly the same size, and if you have multiple hard links, the linked file is just a file size.

All files in the same file are equivalent, the operating system does not differentiate between the sequence of link creation, if a file has two links, then the removal of a file can also be accessed through another file to access the file, you can drop the creation of the link to use the file, but as long as there is a link exists, you can access the file through the connection

Symbolic link (soft link): Create a separate file that allows data to be read to point to the contents of the file it links to. Similar to Windows shortcuts.

The 9 letters in the 1th field represent the permission bits for the file or directory.

R table is read, w represents write, X represents execution (execute)

The first three represent permissions for the owner of the file, and the middle three represents the permissions that the file belongs to, and the last three represents the permissions that other users have.

Suid and GUID resolution:

S:4;g:2;o:1

4777 is rwsrwxrwx. 6777 namely RWSRWSRWX

2nd field: Number of hard links to files

-rw-r--r--1 root root 762 07-29 18:19 exit

If a file is not a directory, this field represents the number of hard links that the file has

The value of the 2nd field is 1, which indicates that file exit has only the name of exit. That is, there is only one hard link to the link.

If you use ln, do a hard link to the file and then view the file, and the 2nd field of the file becomes 2.

[root@localhost ~]# Ln Exit Aexit

[Root@localhost ~]# Ls-l

Total 160

-rw-r--r--2 root root 762 07-29 18:19 Aexit

-rw-r--r--2 root root 762 07-29 18:19 exit

At this point, exit and Aexit are referred to as hard links. Point to a file, no matter which file is modified, the other is also the corresponding change, that is, the same file different file names

Files that are hard linked to each other have the same file node.

[Root@localhost ~]# ls-i Aexit exit

162302 Aexit 162302 Exit

Soft link formatting:

Ln–s source File Destination link file

# Ln-s Exit Bexit

# ls-l

lrwxrwxrwx 1 root 4 08-03 08:27 bexit-> exit

-rw-r--r--1 root root 762 07-29 18:19 exit

Note: The Soft link file node number is not the same;

[Root@localhost ~]# ls-i Bexit exit

161765 Bexit 162302 Exit

If you know how a file has multiple file names (linked files), how do I find the path to his other file name?

Use Ls-i to get its node number, find lookup.

[Root@localhost ~]# Ls-i/etc/sysconfig/network-scripts/ifcfg-eth0

452946/etc/sysconfig/network-scripts/ifcfg-eth0 #节点号为 452946

[Root@localhost ~]# Find/etc-inum 452946

/etc/sysconfig/network-scripts/ifcfg-eth0

2nd field: Link-occupied node

lrwxrwxrwx 1 root 4 08-03 08:27 bexit-> exit

The field file occupies a node, belonging to a soft link (symbolic link)

If it is a directory, the 2nd field represents the number of subdirectories that the directory contains

Creates a new empty directory in which the second field is 2, indicating that there are two subdirectories in the directory.

This default subdirectory is hidden because each directory has a subdirectory that points to itself, "." and a subdirectory that points to its parent directory.

Each time you create a new subdirectory under the directory, the value of the 2nd field in the directory increases by 1, but the field value does not increase when you create a new normal file.

3rd field: File (directory) owner

lrwxrwxrwx 1 root 4 08-03 08:27 bexit-> exit

This field indicates who owns the file. Only the owner of the file has the right to change the file properties. Root has the right to alter any file attributes. For a directory, only the user who owns the directory, or a user with write permissions, has the right to create files in the directory.

If a user is deleted and the user's home directory still exists, ls-l view the file to display a number that represents the front ID number of the user.

Create user test, add it to Wang User group, SU switch:

[Root@localhost ~]# Useradd test

[root@localhost ~]# usermod-g Wang Test #创建用户test and added it to the user group Wang

[Root@localhost ~]# su Test

[Test@localhost root]$ Cd/home/test

[Test@localhost ~]$ Touch Testing

[Test@localhost ~]$ ls-l Testing

-rw-r--r--1 Test Wang 0 08-03 18:02 testing #最后用ls-L See File owner of third field as test

[Test@localhost ~]$ su Root #删除用户test

[Root@localhost ~]# Userdel Test

[Root@localhost ~]# cd/home/test #进入test的家目录 To view the file you just created testing.

[Root@localhost test]# Ls-l

Total 4

-rw-r--r--1 504 Wang 0 08-03 18:02 Testing

The third field becomes a number and this number is the ID number of the original user test. Because the file system has the ID of the owner of each file record file, not the user name.

4th field: The group where the owner of the file (directory) is located

lrwxrwxrwx 1 root 4 08-03 08:27 bexit-> exit

A user can join many groups, but one of them is the primary group, which is the name displayed in the 4th field.

USERADD-G Specifies the primary group where the user is located, and-G specifies another group

USERADD–G Group name User name

5th field: Space occupied by the file (in bytes)

lrwxrwxrwx 1 root 4 08-03 08:27 bexit-> exit

The 5th field represents the file size, or, if it is a directory, the size of the directory. Note the size of the directory itself, not the total size of the directory and the files below it.

6th field: File (directory) last accessed (modified) time

lrwxrwxrwx 1 root 4 08-03 08:27 bexit-> exit

Can modify creation time by Touch # Touch exit

Change the exit creation time to the current time, the file has the last access time, the last modification time, and other attributes.

can be displayed with LS other parameters.

7th field: File name

lrwxrwxrwx 1 root 4 08-03 08:27 bexit-> exit

If it is a symbolic link, there will be a "->" symbol followed by the filename it points to

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.