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

时间:2013-12-31 03:47:50

标签: linux bash

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

$ ls -lt | wc -l

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

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

1 个答案:

答案 0 :(得分:5)

您需要熟悉“man(手册)页面”:

$ man ls

在这种情况下,你会看到:

 -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.

另一种可以看到选项效果的方法是运行ls而不管道wc命令。比较

$ ls

$ ls -l

$ ls -lt