Explanation of "Turn" Linux ls-l

Source: Internet
Author: User
Tags parent directory touch command

Original: http://blog.csdn.net/sjzs5590/article/details/8254527

Take Root's home directory as an example:

As you can see, viewing a directory with the ls-l command will give you a list of 7 fields.

Line 1th: Totals (total)

The number after total refers to the sum of the space occupied by all the files in the current directory. You can use LS–LH to view it or use Ls–alh to view it.

1th field: File attribute field

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

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

The letter "-" indicates that the file is a normal file

The letter "D" means that the file is a directory, the letter "D", is an abbreviation for the Dirtectory (directory)

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

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

The letter "B" represents a block device file (block), generally placed in the/dev directory, the device files are ordinary files and programs access to hardware devices, is a very special file. There is no file size, only one master device number and one secondary device number. An entire block of data is called a block device, such as a hard disk, a disc, etc. The minimum data transfer Unit is a block (typically 512 bytes for a block of data)

The letter "C" means that the file is a character device file (character), typically placed in the/dev directory, one-byte transmission of a device is called a character device, such as a keyboard, a character terminal, etc., the smallest unit of transmitted data is one byte.

The letter "P" indicates that the file is a command pipeline file. Files related to shell programming.

The letter "S" indicates that the file is a sock file. Files related to shell programming.

This important concept of file linking is reiterated here :

The concept of a linked file is similar to a shortcut in Windows. Multiple linked files point to a source file at the same time. The link file is divided into two types: hard link or symbolic link.

In a Linux file system, files that are saved in a disk partition, regardless of the type, assign a number to it, called the inode number of the index node. A soft connection, in fact, is the creation of a new file, which is specifically used to point to other files (that is, the shortcut under Windows, the file is very close to the meaning). Soft connection is a new file, but the role of this file is specifically pointing to a file, delete the soft connection file, it is equal to do not need this connection, and the original existence of the entity original file does not have any relationship, but delete the original file, then the corresponding soft connection is not available (cat that soft link file, then prompt " No this file or directory ")

A hard connection does not create an inode, he only adds 1 to the original Inode link Count field in the file, and therefore hard links are not allowed to span the file system. Instead, the soft link will re-establish an inode, although the structure of the inode is not the same as the rest, he is just a string of information indicating the source file. Once the source file is deleted, the soft connection becomes meaningless. When the hard link deletes the source file, the system call checks the Inode link count value, if he is greater than or equal to 1, then the inode will not be recycled, so the contents of the file will not be deleted, equivalent to delete an index.

Hard links actually create an alias for the file, and the link file and the original file are actually the same file. Can be viewed through ls-i, the inode number of these two files is the same , indicating that they are the same file, and the soft link is established a point, that is, the content of the linked file is a pointer to the original file, they are two files.

Soft links can cross the file system, hard links can not, soft links can be a nonexistent file name (filename) Link (of course, if you vi this soft link file, Linux will automatically create a file named filename), hard links can not (its file must exist, Inode must be present), soft links can be connected to the directory, hard links are not available. Both of these links can be created by command Ln. The default for LN is to create a hard link. Use the-s switch to create a soft link

The 9 letters after the 1th character indicate the permission bit for the file or directory.

R table is read (read), W for write (write), X for Execute (EXECUTE)

The first three represent the permissions of the file owner, and the middle three represents the permissions that the file group owns, and the last three represent the permissions that other users have.

Like what:

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

Indicates that the owner of the file has read and write access to the file, and that the other person (the same group of users and other users only has Read permissions)

In addition, the permission group has some special notation:

[Email protected] ~]# Ll/usr/x11r6/bin/xfree86

-RWs--x--x 1 root root 1960262 2003-02-28/usr/x11r6/bin/xfree86

s means that this is the network interface program "s" is the socket abbreviation. The program will open a network interface during the run.

Other Unix-like systems, such as FreeBSD, also have t -permissions, which indicate a temporary (temporary) file

#ls-L/tmp can see this permission: DRWXRWXRWT the last one is the letter "T".

2nd field: Number of hard links in a file

-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, indicating that this file has only the exit file name. That is, there is only one hard link to the link.

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

At this point, exit and Aexit are called mutual hard links. They point to the same file, regardless of which file is modified, and the other changes accordingly, because they actually point to the same file (that is, different filenames of the same file)

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

As you can see, these two files have the same file node number: 162302

You can set up symbolic links (soft links)in the following format

Ln–s source File Destination link file

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

If you know that a file has multiple file names (linked files), how do I find out where his other filenames are located?

You can use Ls-i to get its node number, and then find it with find, such as/etc/sysconfig/networking/ifcfg-eth0 has more than one file name, to find the file with which it is hard to link to each other

Get it with a node number of 452946

Find again using find:

This gives you the location of the different filenames for the same file.

2nd field: node occupied by link

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

The field file occupies a node and belongs to a soft link (symbolic link)

If it is a directory, the 2nd field represents the number of subdirectories contained in the directory.

Create a new empty directory, the second field of this directory is 2, indicating that there are two subdirectories under the directory. Why is there a two subdirectory under the new directory?

Because each directory has a sub-directory that points to itself. " "and a subdirectory pointing to its parent directory". ", these two default subdirectories are hidden. Ls-a can see

Each time a new subdirectory is created under the directory, the value of the 2nd field in the directory increases by 1, but the field value is not incremented for creating a new normal file.

3rd field: File (directory) owner

lrwxrwxrwx 1 Root root 4 08-03 08:27 bexit-> Exit

This field indicates which user this file belongs to. Linux class systems are multi-user systems, and each file has its own owner. Only the owner of the file has the right to change the file attributes. Of course, the root user has the right to change any of the file attributes. For a directory, only the user who owns the directory, or a user with write permission, has the right to create files in the directory

If a user is deleted for some reason and the user's file still exists, viewing the file with Ls-l displays a number that represents the user's previous ID number.

First create a user test, add it to the Wang User group, and use SU to switch, using Ls–l to view the file owner, then delete the user test, root into the test home directory, to view the file testing just created.

As you can see, the third field is a number, which is the ID number of the original test user. Because the file system records the file owner's ID for each file, not the user name.

4th field: The group where the file (directory) owner resides

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

A user can join a number of groups, but one of them is the primary group, which is the name that appears in the 4th field.

You can specify the user's primary group with-G in Useradd, and the other group with-G

The format is as follows: USERADD–G Group name User name

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

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

The 5th field represents the file size and, if it is a folder (directory), the size of the folder. note the size of the folder itself, not the total size of the folder and the files underneath it.

Many people do not understand the meaning of a folder is a special file, so it is more difficult to understand the meaning of folder size.

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

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

The time the file was created can be modified by the touch command. Such as:

[[email protected] ~]# Touch exit

You can change the creation time of exit to the current time, plus a file with properties such as last access time, last modified time, and so on.

These properties can be displayed with other parameters of LS.

7th field: File name

lrwxrwxrwx 1 root root 4 08-03 08:27 Bexit exit

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

Explanation of "Turn" Linux ls-l

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.