Home  >  Article  >  Operation and Maintenance  >  What is the linux ll command?

What is the linux ll command?

青灯夜游
青灯夜游Original
2022-03-09 15:51:2541828browse

In Linux, the "ll" command refers to the "ls -l" command, which is an alias of the "ls -l" command and is used to display the content list of the directory in long format; the output The information from left to right includes file name, file type, permission mode, number of hard connections, owner, group, file size and file's last modification time, etc.

What is the linux ll command?

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

ll is not a basic command under Linux, it is actually an alias of ls -l.

The meaning of "ls -l"

Displays a list of the contents of the directory in long format. The output information includes file name, file type, permission mode, number of hard connections, owner, group, file size and file's last modification time from left to right.

What is the linux ll command?

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

Line 1: Total

The number after Total refers to the total space occupied by all files in the current directory. You can use ls –lh to view, or ls –alh to view.

Field 1: File attribute field

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

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

  • The letter "-" indicates that the file is an ordinary file

  • The letter "d" indicates that the file is a directory, the letter "d" , is the abbreviation of directory (directory)

    Note: Directory or special file, this special file stores information related to other files or directories

  • The letter "l" means This file is a link file. The letter "l" is the abbreviation of link, similar to the shortcut under windows

  • The letter "b" represents the block device file (block), which is generally placed in the /dev directory Below, device files are the entry points for ordinary files and programs to access hardware devices. They are very special files. There is no file size, just a major and a minor number. A block device that transfers data in one block at a time is called a block device, such as a hard disk, an optical disk, etc. The minimum data transfer unit is a data block (usually the size of a data block is 512 bytes)

  • The letter "c" indicates that the file is a character device file (character), generally Devices placed in the /dev directory and transmitting one byte at a time are called character devices, such as keyboards, character terminals, etc. The minimum unit of data transmission 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.

I would like to reiterate the important concept of file linking:

The concept of linking files is similar to the shortcut in windows. Multiple linked files point to a "source file" at the same time. Linked files are divided into two types: hard links or symbolic links.

In the Linux file system, no matter what type of file is saved in the disk partition, it is assigned a number, called the index node number inode. A soft link is actually a newly created file. This file is specifically used to point to other files (it is very similar to the shortcut file under Windows). A soft link generates a new file, but the function of this file is to point specifically to a certain file. Deleting this soft link file means that this link is not needed and has no relationship with the original existing entity file. But if you delete the original file, the corresponding soft link will be unavailable (cat the soft link file will prompt "there is no such file or directory")

The hard link will not create the inode, it just The original inode link count field of the file is only increased by 1, so hard links cannot cross the file system. On the contrary, soft connections will re-establish an inode. Of course, the structure of inode is different from others. It is just a string information indicating the source file. Once the source file is deleted, the soft link becomes meaningless. When deleting the source file with a hard link, the system call will check the value of the inode link count. If it is greater than or equal to 1, the inode will not be recycled, so the content of the file will not be deleted, which is equivalent to deleting an index.

A hard link actually creates an alias for the file, and the linked file and the original file are actually the same file. You can check it through ls -i. The inode numbers of the two files are the same, indicating that they are the same file; and the soft link establishes a pointer, that is, the content in the linked file is a pointer to the original file. They are two files.

软链接可以跨文件系统,硬链接不可以;软链接可以对一个不存在的文件名(filename)进行链接(当然此时如果你vi这个软链接文件,linux会自动新建一个文件名为filename的文件),硬链接不可以(其文件必须存在,inode必须存在);软链接可以对目录进行连接,硬链接不可以。两种链接都可以通过命令 ln 来创建。ln 默认创建的是硬链接。使用 -s 开关可以创建软链接

第1字符的后面9个字母表示该文件或目录的权限位。

r表是读 (Read) 、w表示写 (Write) 、x表示执行 (eXecute)

其中前三个表示文件拥有者的权限,中间三个表示文件所属组拥有的权限,最后三个表示其他用户拥有的权限。

比如:

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

表示文件的拥有者root对文件有读写权限,其他人(同组用户和其他用户只有读的权限)

另外,权限组还有一些特殊的表示法:

[root@localhost ~]# ll /usr/X11R6/bin/XFree86
-rws--x--x 1 root root 1960262 2003-02-28 /usr/X11R6/bin/XFree86

s表示这个是网络接口程序"s"是socket的缩写。该程序在运行过程中会打开一个网络接口。

其他UNIX类系统如FreeBSD中还有t权限,表示一个临时(temporary)文件

#ls -l /tmp可以看到这样的权限:drwxrwxrwt 它的最后一位是字母"t"

第2字段:文件硬链接数

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

如果一个文件不是目录,此时这一字段表示这个文件所具有的硬链接数,

第2字段的值为1,说明这个文件只有exit这一个文件名。即只有一个指向该链接的硬链接。。

如果使用ln,做一个指向该文件的硬链接再查看该文件,该文件的第2字段就会变成2

What is the linux ll command?

此时exit 和aexit称为互为硬链接。他们指向同一个文件,无论是修改哪一个文件,另一个里也做相应的变化,因为实际上他们指向同一个文件(即同一文件的不同文件名)

互为硬链接的文件具有相同的文件节点。

What is the linux ll command?

可以看出,这两个文件具有相同的文件节点号:162302

可以设置符号链接(软链接),格式如下

Ln –s 源文件 目标链接文件

What is the linux ll command?

注意:软链接时文件节点号不一样;

What is the linux ll command?

如果知道一个文件有多个文件名(链接文件)如何查找他的其他文件名分布在什么地方呢?

可以先用ls -i 获得它的节点号,然后用find查找,如/etc/sysconfig/networking/ifcfg-eth0就具有多个文件名,要查找与它互为硬链接的文件

What is the linux ll command?

得到它的节点号为 452946

再用find查找:

What is the linux ll command?

这样就得到了同一个文件的不同文件名的位置。

第3字段:文件(目录)拥有者

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

该字段表示此文件是属于哪个用户。linux类系统都是多用户系统,每个文件都有它的拥有者。只有文件的拥有者才具有改动文件属性的权利。当然, root用户具有改动任何文件属性的权利。对于一个目录来说,只有拥有该目录的用户,或者具有写权限的用户才有在目录下创建文件的权利

如果某一个用户因为某种原因,被删除,而该用户的文件还存在,那么用ls -l 查看该文件将显示一个代表用户存在前ID号的数字。

先创建一个用户test,将其加入wang用户组,并用su切换,使用ls –l查看文件拥有者,随即删除用户test,用root进入test家目录,查看刚刚创建的文件testing。

What is the linux ll command?

可以看到,第三字段成了一个数字,这个数字是原test用户的ID号。因为文件系统对每个文件记录文件所有者的ID,而非用户名。

第4字段:文件(目录)拥有者所在的组

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

一个用户可以加入很多个组,但是其中有一个是主组,就是显示在第4字段的名称。

可以在useradd的时候用-g指定该用户所在的主组,用-G指定其他组

格式如下:Useradd –g 组名 用户名

第5字段: 文件所占用的空间(以字节为单位)

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

第5字段表示文件大小,如果是一个文件夹(目录),则表示该文件夹的大小。请注意是文件夹本身的大小,而不是文件夹以及它下面的文件的总大小。

很多人不能理解文件夹是一个特殊的文件的含义,这样的话理解文件夹大小的含义就比较困难了。

第6字段:文件(目录)最近访问(修改)时间

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

文件创建的时间可以通过touch命令来修改。如:

[root@localhost ~]# touch exit

可以把exit的创建时间修改为当前时间,另外,一个文件还有最后访问时间,最后修改时间等属性。

这些属性可以用ls 的其它参数显示出来。

第7字段:文件名

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

如果是一个符号链接,那么会有一个 “->" 箭头符号,后面根一个它指向的文件名

相关推荐:《Linux视频教程

The above is the detailed content of What is the linux ll command?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn