linux - 如何使用 xargs 将 ls 通过管道传输到 cat 中,以便列出文件名?

标签 linux pipe cat ls xargs

使用cat输出指定目录下的*.txt文件,如何在每个文件前插入文件名作为“break”?

file #1
contents of file

file #2
contents of file

理想情况下是一些易于内存的 bash 命令。

另见:

Why not pipe list of file names into cat?

最佳答案

@0stone0 回答的另一个选项 您可以使用 tail 代替 cat:

tail -n +1 *

输出:

==> file-1.txt <==
contents of file


==> file-2.txt <==
contents of file

关于linux - 如何使用 xargs 将 ls 通过管道传输到 cat 中,以便列出文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65217910/

相关文章:

delphi - Delphi 中用于命令提示符的管道

android - Logcat 为什么叫 LogCAT

linux - 在文本文件文件中搜索数字并指定范围和长度 Grep

linux - 什么是 linux 中的链式 irq,什么时候需要使用它们?

c - Linux 内核 : get function address for kernel driver

linux - Vagrant + Composer + Windows/nfs/git 错误

bash - 复制命令输出,将未处理后的副本打印到标准输出并将处理后的副本存储到文件中

angular - 如何在 Angular 2 模板中对数据和输出进行分组——使用管道?

linux - 在 linux 上比较两个日期时是否也考虑了时区差异

linux - 如何使用dos批处理删除文件中的Ctrl-Z