Linux ls命令教程和示例

Linux operating system provides a lot of different functionalities with different tools and commands. ls is the most used command in linux. ls is the arm and leg of Linux system administrator. ls provides a lot of different functionalities with different options.

Linux操作系统使用不同的工具和命令提供了许多不同的功能。 ls是Linux中最常用的命令。 ls是Linux系统管理员的一臂之力。 ls提供了许多具有不同选项的不同功能。

曼斯 (Man ls)

Man page of ls command can be retrieved like below.

可以按以下方式检索ls命令的手册页。

$ man ls
Man ls
Man ls
曼斯

列出文件(List Files)

We can list files and folders simple without providing any parameter. This will list all files except hidden files those names starts with .

我们可以简单地列出文件和文件夹,而无需提供任何参数。 这将列出所有文件(隐藏名称以开头的文件除外) .

$ ls
List Files
List Files
列出文件

根据修改日期列出文件(List Files According To Modification Date)

-t parameter make listing according to their modification date. REcently modified file will be listed in the upper side

-t参数根据其修改日期列出。 最近修改的文件将列在上方

$ ls -t
List Files According To Modification Date
List Files According To Modification Date
根据修改日期列出文件

每行显示一个文件(Display One File Per Line)

We can set 1 file will be listed in single line. This is generally useful for providing file list as an input into other commands or applications.

我们可以设置1个文件将在单行中列出。 通常,这对于提供文件列表作为其他命令或应用程序的输入很有用。

$ ls -1
Display One File Per Line
Display One File Per Line
每行显示一个文件

显示详细的文件信息(Show Detailed File Information)

We can get more details about files and folders with -l option.

我们可以使用-l选项获取有关文件和文件夹的更多详细信息。

$ ls -l
Show Detailed File Information
Show Detailed File Information
显示详细的文件信息
  • drwxr-xr-x is permission information

    drwxr-xr-x是权限信息

  • root root is user and group information. It is related with permission

    root root是用户和组信息。 与许可有关

  • 4096 is the size in byte . Folders have same size

    4096为字节大小。 文件夹大小相同

  • Oct  6  12:08 is the modification date

    10月6日12:08是修改日期

  • Amsterdam is the file or folder name

    阿姆斯特丹是文件或文件夹的名称

显示尺寸信息人类可读格式(Display Size Information Human Readable Format)

We see that size is in byte format we can change is MB,GB format according to its size

我们看到大小为字节格式,我们可以根据其大小更改为MB,GB格式

$ ls -lh
Display Size Information Human Readable Format
Display Size Information Human Readable Format
显示尺寸信息人类可读格式

显示目录信息(Display Directory Information)

We can list only directory with -d  option. It will not list files and directories under it.

我们只能使用-d选项列出目录。 它不会列出其下的文件和目录。

$ ls -dl tmux
Display Directory Information
Display Directory Information
显示目录信息

冲销单清单(Reverse Order List)

We can list files and folders according to their names, modification date. But we can reverse order with -r parameter

我们可以根据文件和文件夹的名称,修改日期列出它们。 但是我们可以使用-r参数反转顺序

$ ls -ltr
Reverse Order List
Reverse Order List
冲销单清单

显示隐藏文件(Display Hidden Files)

Linux world hidden files are pretended with a point before their name. By default ls do not list these files. We can list them too with -a 

Linux世界隐藏文件的名称之前带有一个点。 默认情况下,ls不列出这些文件。 我们也可以使用-a列出它们

$ ls -l -a
Display Hidden Files
Display Hidden Files
显示隐藏文件

递归显示文件(Display Files Recursively)

We can display files recursively  with -R parameter. Recursively means we will list folders and their contents and this goes to the deepest path.

我们可以使用-R参数递归显示文件。 递归意味着我们将列出文件夹及其内容,这是最深的路径。

$ ls -R
Display Files Recursively
Display Files Recursively
递归显示文件

显示文件索引号(Display Files Inode Numbers)

Inode is file system related information about files and folders. Inodes generally do not needed daily usage but sometimes it can be important.

Inode是有关文件和文件夹的文件系统相关信息。 索引节点通常不需要日常使用,但有时可能很重要。

$ ls -l -i
Display Files Inode Numbers
Display Files Inode Numbers
显示文件索引号

显示用户ID(UID)和组ID(GUID)(Display User Id (UID) and Group Id (GUID))

We can list user and group id of files according to their names

我们可以根据文件名列出用户名和组名

$ ls -n
Display User Id (UID) and Group Id (GUID)
Display User Id (UID) and Group Id (GUID)
显示用户ID(UID)和组ID(GUID)
  • 0 0 are user and group id of root

    0 0是root用户和组ID

LEARN MORE  How To Find and List Large Files and Directories In Linux?
了解更多如何在Linux中查找和列出大文件和目录?

颜色文件分类 (Classification of Files with Colors)

Coloring will easy viewed of the files and folders. We can colorize the ls command output with the --color=auto option.

着色将很容易查看文件和文件夹。 我们可以使用--color=auto选项为ls命令输出着色。

$ ls --color=auto
Classification of Files with Colors
Classification of Files with Colors
颜色文件分类

ls的别名(Alias for ls)

We can make providing parameters more practical. We can define alias for ls commands with parameters.

我们可以使提供参数更加实用。 我们可以使用参数为ls命令定义别名。

$ alias ll="ls -lh"
Alias for ls
Alias for ls
ls的别名
  • alias create ll command

    别名创建ll命令

  • ls -lh is the actual command where it will be called ll is issued

    ls -lh是将被称为ll的实际命令

以/结尾列出文件和目录(List Files and Directories with / At The End)

To in scripts or other types directories and files can be listed with at the end with -F

在脚本或其他类型中的To可以在目录末尾以/ F开头/列出-F

$ ls -F
List Files and Directories with / At The End
List Files and Directories with / At The End
以/结尾列出文件和目录

按大小排序文件(Sort Files By Size)

One of the most useful option of ls command is sorting files according to their sizes. This will list bigger files first and then decreasingly.

ls命令最有用的选项之一是根据文件的大小对文件进行排序。 这将先列出较大的文件,然后再减少。

$ ls -lS
Sort Files By Size
Sort Files By Size
按大小排序文件

带有示例信息Linux ls命令教程(Linux ls Command Tutorial With Examples Infografic)

Linux ls Command Tutorial With Examples Infografic

翻译自: https://www.poftut.com/linux-ls-command-tutorial-with-examples/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值