“排序”和“排序”之间的区别输出”和“排序输出”
Linux 中的区别
sort < output
我只是想知道:和
sort output
。它到底是如何运作的?
I just want to know the difference between:
sort < output
and
sort output
in Linux. How does it work exactly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这已经在 unix.stackexchange 上进行了讨论:标准输入之间的性能差异和命令行参数
中
sort < file
shell 执行重定向。它打开文件并将 stdin 文件描述符传递给读取它的 sort 命令。在
sort file
中,sort
命令打开文件,然后读取它。This has been discussed on unix.stackexchange here: Performance difference between stdin and command line argument
In
sort < file
the shell performs redirection. It opens the file and passes thestdin
file descriptor to thesort
command which reads it.In
sort file
, thesort
command opens the file and then reads it.排序< output
告诉 shell 使用文件output
的内容并将其转储到标准输入以进行命令排序。sort output
告诉命令sort
使用磁盘上的文件output
作为源。许多 UNIX 命令将接受标准输入或文件作为输入。接受标准可以更轻松地链接命令,通常用于诸如 ps aux | 之类的事情。 grep“我的进程”|排序。 (列出所有进程,按“我的进程”过滤,对行进行排序)。
sort < output
is telling the shell to use the contents of the fileoutput
and dump it to standard in for the command sort.sort output
is telling the commandsort
to use the fileoutput
on disk as it's source.Many unix commands will accept either standard in or a file as input. The acceptance of standard in allows easier chaining of commands, often for things like
ps aux | grep "my process" | sort
. (List all processes, filter by "my process", sort lines).使用
sort < input
shell 将运行sort
命令,并将其输入附加到文件“input”中。使用
sort input
,shell 将运行sort
命令,并将字符串input
作为参数提供给它。然后,sort
命令将打开文件以读取其内容。With
sort < input
the shell will run thesort
command, and attach its input to the file 'input'.With
sort input
the shell will run thesort
command, and give it as parameter the stringinput
. Thesort
command will then open the file to read it- content.实际上没有什么区别。
排序<输出
使用 shell 的一项称为文件重定向的功能(请参见此处< /a>)shell 打开平铺文件
output
并将该打开的文件作为stdin
附加到排序程序。sort output
将output
文件名作为排序的命令行参数。sort 与许多采用文件名作为参数的实用程序一样,如果您不将文件名作为参数,则将尝试从 stdin 读取输入,例如此处的第一种情况。在这两种情况下,sort 都会读取输出文件的内容,对其进行排序,然后将结果写入 stdout。
Effectively there is no difference.
sort < output
uses a feature of the shell called file redirection (see e.g. here)The shell opens tile file
output
and attaches that open file asstdin
to the sort program.sort output
gives theoutput
filename as an command line argument to sort.sort, as many utilities that takes a filename as an argument, will try to read input from
stdin
if you do not give it a filename as an argument, such as in the first case here. In both cases, sort will read the content of theoutput
file, sort it, and write the result to stdout.