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
列出文件(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 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
每行显示一个文件(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
显示详细的文件信息(Show Detailed File Information)
We can get more details about files and folders with -l option.
我们可以使用-l选项获取有关文件和文件夹的更多详细信息。
$ ls -l
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 Directory Information)
We can list only directory with -d option. It will not list files and directories under it.
我们只能使用-d选项列出目录。 它不会列出其下的文件和目录。
$ ls -dl tmux
冲销单清单(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
显示隐藏文件(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 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 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
显示用户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
0 0 are user and group id of root
0 0是root用户和组ID
颜色文件分类 (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
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 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
按大小排序文件(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
带有示例信息Linux ls命令教程(Linux ls Command Tutorial With Examples Infografic)
翻译自: https://www.poftut.com/linux-ls-command-tutorial-with-examples/