ls的输出|wc -l [英] Output of ls | wc -l

查看:83
本文介绍了ls的输出|wc -l的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常 wc -l <​​/code>命令的输出给出文件中的行数.但是,当我们将 ls 命令的输出传递给它时,似乎可以正确显示当前工作目录中的文件,目录和链接的数量.

Normally the output of wc -l command gives the number of lines in a file. But, when we pipe the output of ls command to it, it seems to show the number of files and directories and links in the current working directory correctly.

我的问题是 ls 命令的输出在同一行中显示某些文件和目录的名称.因此,为什么在这种情况下使用 ls |与 ls -l | wc -l <​​/code>提供相同的输出wc -l <​​/code>.预先感谢.

My question is that the output of the ls command displays names of some files and directory in the same line. So, why in this case using ls | wc -l gives the same output, as compared to ls -l | wc -l. Thanks in advance.

推荐答案

ls 检测到它正在通过管道传递到另一个程序而不是控制台,并每行输出一个文件/目录.你可以试试 ls |猫以查看此行为.

ls detects that it's being piped to another program instead of to the console, and outputs one file/directory per line. You can try ls | cat to see this behavior.

这篇关于ls的输出|wc -l的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆