Linux ll after the meaning of the field and how to modify the file's owner and user group __linux

Source: Internet
Author: User

Ls-l List Information Detailed

When we use the Ls-l command to view the Shishi information of files and subdirectories in a directory, we get a detailed list of file and directory names. This listing contains the attributes of the file, the user, the owning group, the creation time, the file size, and so on. What does this information mean? There are a lot of beginners who don't know much about these, so they want to Shishi explain the list of files in the Ls-l command. Each field means

Take the author's computer/root directory as an example:

[Root@gucuiwen root]# LL

Total Dosage 4055

-rw-r--r--1 root root 1581 November 18:14 anaconda-ks.cfg

Drwxr-xr-x 2 Root 208 December 1 13:50 babylinux

-rw-r--r--1 root root 1474560 November 15:02 babylinux.img

-rw-r--r--1 root root 26829 November 15:10 babylinux.png

lrwxrwxrwx 1 Root 9 January 4 11:06 disk1.link.png-> disk1.png

-rw-r--r--1 root 3209 November 12:07 disk1.png

-rw-r--r--1 root 692 November 13:16 disk2.png

-rw-r--r--1 root 718 November 13:30 disk3.png

DRWX------8 Root 392 January 4 08:40 Evolution

-rwxr-xr-x 1 root 13695 November 16:51 fangkuai.sh

Drwxr-xr-x 2 root root 208 December 12:06 FreeBSD

-rw-r--r--1 root root 2315 November 17:19 getmbr.png

Brw-r-----1 Root 3, 1 January 4 11:06 hda1

Drwxr-xr-x 2 root root 296 December 11:53 htmls

-rw-r--r--1 root root 21369 November 18:12 Install.log

-rw-r--r--1 root root 3024 November 18:12 install.log.syslog

-rw-r--r--1 root 293 January 4 10:51 ls.txt

-rw-r--r--1 root root 2237702 November 15:09 Magick.miff

-rw-r--r--1 root root 13493 November 17:31 mbr1.png

-rw-r--r--1 root root 8123 November 17:42 mbr2.png

-rw-r--r--1 root 512 November 16:10 Mbr.dat

-rw-r--r--1 root 64512 November 15:33 Partition.doc

-rw-r--r--1 root 49887 November 15:32 partition.sxw

-rw-r--r--1 root root 1541 December 13:14 passwd

-rw-r--r--1 root root 46320 November 17:28 screenshot-1.png

-rw-r--r--1 root root 44145 November 17:32 screenshot-2.png

-rw-r--r--1 root root 43732 November 17:13 screenshot.png

Drwxr-xr-x 3 Root 72 January 4 10:49 test

-rw-r--r--1 root root 0 December 10:44 tset

Crw-r-----1 Root 4, 65 January 4 11:08 ttyS1

-rw-r--r--1 root 9754 December 1 11:25 x.sxw

-rw-r--r--1 root 8704 November 29 12:22 employee information. xls

-rw-r--r--1 root 19456 November 26 17:14 Move the plan. xls

As you can see, using the Ls-l command to view a directory will get a list of 9 fields.

#######################

Line 1th: Total amount

#######################

This value is the and (in K) of the 5th field of all files and directories listed in the directory. That is, the size of the directory. Notice the difference between the sum of the files in the directory and the file under the subdirectory. This number is not the same size as the du/root. You can use the awk command to validate.

Add the value from the 5th field in awk:

[Root@gucuiwen root]# ls-l |awk ' begin{sum=0}{sum+=$5}end{print sum} '

4104092

into a unit of K:

[Root@gucuiwen root]# ls-l |awk ' begin{sum=0}{sum+=$5}end{print sum/1024} '

4007.9

Value obtained by ls-l:

Total Dosage 4055

Value obtained by Du-sh/root:

[Root@gucuiwen root]# Du-sh/root

127m/root

You can see that the sum of the 5th field is the same as the total displayed (because of the difference in the specific algorithm, slightly different). The resulting value is actually the size of the root directory (the root directory is considered a special file to understand what the size of the directory is). The values obtained by DU are the sum of the sizes of all files and subdirectories under the root directory.

########################

1th field:

File property fields

########################

The File property field has a total of 10 letters, the first letter represents the file type, and if the letter is a minus sign "-", the file is a normal file. The letter "D" indicates that the file is a directory, the letter "D", and is an abbreviation for the Dirtectory (directory). Please note that A directory or a folder is a special file, this special file is stored in other files and folders related information.

If the letter is "L", indicates that the file is a symbolic link. The concept of symbolic links is similar to shortcuts in Windows. The letter "L" is the abbreviation for link (link). In Unix class systems, a file can have multiple file names, and a file's multiple file names are called Hard links ( Hard link). These headers can point to the same file, delete one of the file names and can not delete it, only to delete all the hard links to the file, the space occupied by the file is actually released, the file is actually deleted. This is very different from windows. Windows does not allow a file to have more than two file names, and if this is the case, it is considered a file system error. If you've ever played debug under Windows, you can use debug to modify the root directory on a floppy disk. Make a file have two file names at the same time. But when modified, it is considered a cross link error to monitor with ScanDisk.

The first is a representation of block device files (blocks) with B, and the device file is a special file which is the entrance to the hardware device. It has no file size, only one main device number and one auxiliary device number. The hda1 above is a device file, Has the main equipment number 3 and the auxiliary equipment number 1. Represents the first partition of the first hard disk.

In addition, if the first letter is C to indicate that the file is a character device file (character), a device that transmits one byte at a time is called a character device, such as a keyboard, a character terminal, and so on, and the smallest unit of data transmission is one byte. Once a piece of data is called a block device, such as a hard disk, CD-ROM and so on. The smallest data transmission unit is one block (usually a data block size is 512 bytes).

The next 9 letters in the first field represent the permissions for the file.

R table is read (read) w indicates write x expression Execution (execute)

The first three represent the permissions of the file owner, the middle three represents the group user rights, and the last three represent other user rights.

Like what:

-rw-r--r--1 root root 1581 November 18:14 anaconda-ks.cfg

Indicates that the owner of the file root has read and write access to the file, and that others (the same group of users and other users have only Read permission)

In addition, permission groups have special representations. For example,/USR/X11R6/BIN/XFREE86 has the following permissions:

[Root@gucuiwen root]# Ll/usr/x11r6/bin/xfree86

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

where s indicates that the network interface program "s" is the abbreviation of the socket. The program opens a network interface during operation.

Other Unix class systems, such as FreeBSD, also have the T permission to represent a temporary (temporary) file

You can see such a permission in FreeBSD with LS-L/tmp:

Drwxrwxrwt

The last one was the letter "T."


-RWX------: The file owner has read, write, and execute permissions on the file.
-rwxr―r--: The file owner has read, write, and execute permissions, and other users have Read permission.
-rw-rw-r-x: The file owner and the same group of users have read and write permissions to the file, while other users have only read and execute permissions.
Drwx--x--x: Directory owners have access to read and write and access to the directory, other users can access the directory, but can not read any data.
DRWX------: Other users have absolutely no permissions on the directory except that the directory owner has full permissions.

###############################

2nd Field

Number of file hard links or directory subdirectories

###############################

If a file is not a directory then this field indicates the number of hard links that this file has, that is, the total number of filenames in this file. View First file:

-rw-r--r--1 root root 1581 November 18:14 anaconda-ks.cfg

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

If I use ln, do a hard link to the file, and then view the file, the 2nd field of that file becomes 2:

[Root@gucuiwen root]# Ln anaconda-ks.cfg anaconda-ks.cfg.hardlink

[Root@gucuiwen root]# Ls-l

Total dosage 4071

-rw-r--r--2 root root 1581 November 18:14 anaconda-ks.cfg

-rw-r--r--2 root root 1581 November 18:14 Anaconda-ks.cfg.hardlink

At this point, anaconda-ks.cfg and Anaconda-ks.cfg.hardlink are referred to as hard links. They point to the same file, no matter which file is modified, and the other changes accordingly because in fact they point to the same file.

Use Ls-i anaconda-ks.cfg to view its file nodes (Inode)

Files that are hard linked to each other have the same file node. Here is the validation experiment:

[Root@gucuiwen root]# ls-i anaconda-ks.cfg

18102 anaconda-ks.cfg

[Root@gucuiwen root]# ls-i Anaconda-ks.cfg.hardlink

18102 Anaconda-ks.cfg.hardlink

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

If you know that a file has multiple file names, how do you find out where the other file names are located?

You can first use Ls-i to get its node number, and then use Find lookup, such as/etc/sysconfig/networking/devices/ifcfg-eth0 has multiple file names, I want to find a hard link with it:

[Root@gucuiwen devices]# ls-i/etc/sysconfig/networking/devices/ifcfg-eth0

147181/etc/sysconfig/networking/devices/ifcfg-eth0

It's got a node number of 147181.

And then find it by finding:

[Root@gucuiwen devices]# Find/etc-inum 147181

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.