命令ls -lt |的含义 wc -l

Pro*_*mer -2 linux bash

我的朋友刚刚通过这个命令来计算目录中的文件数:

$ ls -lt | wc -l
Run Code Online (Sandbox Code Playgroud)

有人可以帮我清除这个命令的含义吗?我知道那ls就是列出所有文件.但是什么-lt意思呢?

另外,如果我ls | wc -l没有-lt选项,我会得到不同的计数.为什么会这样?

Wil*_*ler 5

你想要熟悉"man(手册)页面":

$ man ls
Run Code Online (Sandbox Code Playgroud)

在这种情况下,您将看到:

 -l      (The lowercase letter ``ell''.)  List in long format.  (See below.)  If
         the output is to a terminal, a total sum for all the file sizes is
         output on a line before the long listing.
 -t      Sort by time modified (most recently modified first) before sorting the
         operands by lexicographical order.
Run Code Online (Sandbox Code Playgroud)

另一种可以看到选项效果的方法是在ls没有管道的情况wc下运行命令.相比

$ ls
Run Code Online (Sandbox Code Playgroud)

$ ls -l
Run Code Online (Sandbox Code Playgroud)

$ ls -lt
Run Code Online (Sandbox Code Playgroud)

  • 因为`-l`选项将文件总数显示为其中一行.例如,"总共32". (2认同)