Original link: http://jz20080153.blog.sohu.com/161554070.html
Ls-l List Information Detailed
When we use the Ls-l command to view the Keyholder information of files and subdirectories in a directory, we get a detailed list of file and directory names. This listing contains information about the properties of the file, the user, the group, the creation time, the file size, and so on. What does this information mean? There are a lot of beginners who do not understand these, so want to Keyholder to explain the file list with ls-l command each field meaning
Take the/root catalogue of the author's computer as an example:
[email protected] root]# LL
Total Dosage 4055
-rw-r--r--1 root root 1581 November 18:14 anaconda-ks.cfg
Drwxr-xr-x 2 root 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 root 9 January 4 11:06 disk1.link.png-disk1.png
-rw-r--r--1 root root 3209 November 12:07 disk1.png
-rw-r--r--1 root root 692 November 13:16 disk2.png
-rw-r--r--1 root root 718 November 13:30 disk3.png
drwx------8 root root 392 January 4 08:40 Evolution
-rwxr-xr-x 1 root 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 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 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 root 512 November 16:10 Mbr.dat
-rw-r--r--1 root root 64512 November 15:33 Partition.doc
-rw-r--r--1 root 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 root 72 January 4 10:49 test
-rw-r--r--1 root root 0 December 10:44 tset
Crw-r-----1 root root 4, 65 January 4 11:08 ttyS1
-rw-r--r--1 root root 9754 December 1 11:25 x.sxw
-rw-r--r--1 root root 8704 November 29 12:22 employee information. xls
-rw-r--r--1 root 19456 November 26 17:14 move thousand plan. xls
As you can see, viewing a directory with the ls-l command will give you a list of 9 fields.
#######################
Line 1th: Total amount
#######################
This value is the sum (in K) of the 5th field of all files and directories in this directory, which is the size of the directory. Please note that the sum of the files and subdirectories under the directory is distinguished. This number is different from the size of the du/root. You can use the awk command to verify.
The value obtained by adding the 5th field in awk:
[[email protected] root]# ls-l |awk ' begin{sum=0}{sum+=$5}end{print sum} '
4104092
Converted to K:
[[email protected] root]# ls-l |awk ' begin{sum=0}{sum+=$5}end{print sum/1024} '
4007.9
Values obtained with ls-l:
Total Dosage 4055
Values obtained with Du-sh/root:
[Email protected] root]# Du-sh/root
127m/root
You can see that the sum of the 5th field gets the same value as total (because the specific algorithm differs slightly). The resulting value is actually the size of the root directory (the root directory is considered to be a special file, so you can understand what the size of the directory is). The value of Du is the sum of the total size of files and subdirectories under the root directory.
########################
1th field:
File attribute fields
########################
The file attribute field has a total of 10 letters, the first letter indicates the file type, if the letter is a minus "-", then the file is a normal file. The letter "D" means that the file is a directory, the letter "D", is an abbreviation for 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", it means that the file is a symbolic link. The concept of symbolic links is similar to shortcuts in Windows. The letter "L" is the abbreviation of link. In Unix class systems, a file can have multiple filenames, and multiple filenames of a file are called Hard links ( Hard link). These file headers can point to the same file, delete one of the filenames and cannot delete the file, only to the file to delete all the rigid links, the space occupied by the file is really released, the file is really deleted. There's a big difference between windows, A file with more than two file names is not allowed in Windows and is considered a file system error if this is the case. If you have previously played debug in Windows, you can modify the root directory on a floppy disk by using Debug. Causes a file to have two filenames at the same time. However, when modified and monitored with ScanDisk, it is considered a cross-link error.
The representation of a block device file (block) begins with a B, and the device file is an entry for normal files and programs to access the hardware device, which is a very special file. It has no file size, only one master device number and one secondary device number. The hda1 above is a device file, Has the main device number 3 and the auxiliary device number 1. Represents the first partition of the first hard disk.
In addition, if the first letter C means 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 transmitted data is a byte. A whole block of data is called a block device, such as a hard disk, CD-ROM and so on. The minimum data transfer unit is a block of data (typically 512 bytes for the size of a chunk).
The 9 letters after the first field represent the permissions for the file.
R table is read (read) w indicates write (write) x represents execute (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 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. For example,/USR/X11R6/BIN/XFREE86 has the following permissions:
[Email protected] root]# Ll/usr/x11r6/bin/xfree86
-rws--x--x 1 root root 1960262 2003-02-28/usr/x11r6/bin/xfree86
where s means that this is the network interface program "s" is the abbreviation of the socket. The program opens a network interface during operation.
Other Unix-like systems, such as FreeBSD, also have T-permissions, which indicate a temporary (temporary) file
In FreeBSD, you can see this privilege with LS-L/tmp:
Drwxrwxrwt
The last one is the letter "T".
###############################
2nd Field
Number of hard links or directory subdirectories of a file
###############################
If a file is not a directory then this field indicates the number of hard links that the file has, that is, how many filenames the file has in total. View the first file:
-rw-r--r--1 root root 1581 November 18:14 anaconda-ks.cfg
The value of the 2nd field is 1, which means that this file only has a filename of anaconda-ks.cfg. That is, there is only one hard link to the link.
If I use ln to make a hard link to the file and then view the file, the 2nd field of the file becomes 2:
[Email protected] root]# LN anaconda-ks.cfg anaconda-ks.cfg.hardlink
[Email protected] 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, regardless of which file is modified, and the other changes accordingly because they actually point to the same file.
Use Ls-i anaconda-ks.cfg to view its file node (inode)
Files that are hard-linked to each other have the same file nodes. Here is the validation experiment:
[Email protected] root]# ls-i anaconda-ks.cfg
18102 anaconda-ks.cfg
[Email protected] 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 filenames, how do you 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/devices/ifcfg-eth0 has more than one file name, I want to find the files that are hard-linked to it:
[Email protected] devices]# ls-i/etc/sysconfig/networking/devices/ifcfg-eth0
147181/etc/sysconfig/networking/devices/ifcfg-eth0
Get it with a node number of 147181
Find again using find:
[Email protected] devices]# Find/etc-inum 147181
/etc/sysconfig/networking/devices/ifcfg-eth0
/etc/sysconfig/networking/profiles/default/ifcfg-eth0
This gives you the location of the different filenames for the same file.
*************************************
If it is a directory, the meaning of the 2nd field:
**************************************
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 the directory has two subdirectories. Why are there two subdirectories under the new directory?
Because each directory has a subdirectory that points to itself "." and a subdirectory that points to its parent directory "..", these two default subdirectories are hidden. Use Ls-a to 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 owner
###############################
This field indicates which user this file belongs to. Unix class systems are multi-user systems, each with 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.
Here is the demo:
First create a user and then su past:
[Email protected] root]# useradd gucuiwen-g users
[Email protected] root]# Su-gucuiwen
Create a test file with the new user:
[email protected] gucuiwen]$ Touch testfile
[Email protected] gucuiwen]$ ls-l testfile
-rw-r--r--1 Gucuiwen users 0 January 4 16:31 testfile
Finally, with Ls-l, the file owner of the third field is Gucuiwen
Then I will gucuiwen the user to delete:
[Email protected] root]# Userdel Gucuiwen
[Email protected] root]# cd/home/gucuiwen/
[Email protected] gucuiwen]# ls-l
Total dosage 0
-rw-r--r--1 501 Users 0 January 4 16:31 testfile
As you can see, the third field is a number, which is the ID number of the original Gucuiwen 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 owner resides
###############################
The concept of a group can be imagined as a team that works together to complete a project. Through the concept of a group, you can control the file to be viewed, modified, or run by a particular user. Not beat him, either, or let it all be seen.
A user can join a number of groups, but one of them is the primary group, which is the name shown in the 4th field.
You can specify the user's primary group with-G in AddUser and specify the other groups with-G.
##############################
5th field:
File file size (in bytes)
###############################
The 5th field represents the file size, or, if it is a folder, 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 Creation Month
###############################
That's not much to say.
###############################
7th field:
File creation Date
###############################
###############################
8th field:
File creation time
###############################
The time the file was created can be modified by the touch command. For example:
#touch testfile
You can modify the Testfile creation time to the current time.
For more information on touch, see the linked document.
#man Touch
In addition, a file has properties such as last access time, last modified time, and so on.
These properties can be displayed with other parameters of LS.
###############################
9th field:
Filename
###############################
If it is a symbolic link, there will be a "-a" arrow symbol, followed by a filename that it points to.
Compression command (http://wenku.baidu.com/view/23d9caf9aef8941ea76e05da.html ):
TAR–CF name. tar file
Re-compress: tar–rf name. tar file
Decompression command: TAR–XVF name. Tar
Linux Learning Command ll post field explanation (RPM)