Ls是Linux和UNIX中经常使用的命令之一,了解这个命令是很重要的,Ls命令列出了一个目录中的文件或目录的名称。
ls命令按字母顺序对文件进行排序,并输出到标准控制台。当ls命令被执行时,Linux服务器会进行编码排序,并按字母顺序输出文件。
在Linux中,文件的元数据被存储在一个数据结构中,包括文件所有者、文件访问权限和文件类型。在有组织的文件系统数据结构中,每个inode是一个唯一的索引号。
ls是Unix/Linux操作系统的基本命令之一。
ls命令可以在 bash shell以及Unix的CentOS。
ls命令的语法用法
$ls (options) (file name or directory)
ls命令的语法如上所示,ls命令的例子如下所示
如何使用ls命令显示目录的内容
bash-3.2$ ls
cloud.txt directory1
```
ls command without options displays the files and directories in a current directory
```markup
bash-3.2$ ls
cloud.txt directory1
```
**How to list the inode information using ls command line**
```markup
$ls -l filename
12345 filename
```
here 12345 is index number
l without options list the files and in the directory
**How to list the files and directories in a given path**
```markup
$ls -l
```
ls command with option -l list out the long file format information about files and directories
**How to list the files based on sorting order modification time.**
```markup
$ls -t
```
ls command with option -t displays the recently modified file first and so on
**How to list directories using commands**
```markup
$ls -d
```
ls command with option -d outputs a list of directories in a given path, but not subdirectories
**How to print the files without doing the sorting?**
```markup
$ls -f or ls -U
```
ls command do the sort the files alphabetical and outputs it, Suppose In a given directory, if there 500 files, To view all these files, if ls command is supplied without any arguments, server does sorting of this file's inode and takes more time in hours, so in this case we need to use ls command with option -f to list the filenames without doing sorting
**How to display content of files/directory recursively**
to list the files in directories and subdirectory or recursive directories
```markup
$ ls -R
T
**How to show hidden files in command line**
```markup
$ ls -a or ls -A
带有选项-a的ls命令会输出正常文件和隐藏文件。为了区分正常文件和隐藏文件,总是以'.'隐藏文件