linux - 为什么 ls 和 ls -l linux 命令之间的计数不同?

标签 linux bash shell unix command

我有一个包含多个文件的目录,需要检查其中存在的文件数。

我尝试了以下两个命令:

ls | wc -l
ls -l | wc -l

并发现在使用这两个命令时存在差异。 (即,与第一个命令相比,第二个命令的文件数量更大。)

我想知道这两个命令中发生的变化。

最佳答案

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

因此 ls -l 添加一个标题行,说明文件的“总”大小:

$ ls -l /
total 65
-r--r--r--   1 root  wheel  6197 May 11 21:57 COPYRIGHT
drwxr-xr-x   2 root  wheel  1024 Jun  1 16:02 bin
drwxr-xr-x   9 root  wheel  1536 Jun  1 16:02 boot
dr-xr-xr-x   8 root  wheel   512 Jul  7 20:16 dev
.......

关于linux - 为什么 ls 和 ls -l linux 命令之间的计数不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38348582/

相关文章:

c - gcc -nostdlib 和 mudflap

bash - 用于截断大文件的 Unix shell 脚本

linux - 如何正确停止shell脚本?

linux - 监控重启程序脚本

linux - Linux 中 ls 和 "exec ls"有什么区别

python - 在无限while循环中在shell脚本中一起运行多个程序

linux - 为 Unix/Linux 命令设置全局默认选项的一行 - 最佳实践

linux - 安装 ssmtp 用于发送电子邮件后的虚拟 cron 作业

linux - 将 .TXT 转换为 .XLSX,并保留每个单元格的数据类型 "Text"

Linux 上的 Python 版本