Thu*_*fir 5 linux ls pipe xargs cat
为了用于cat
输出*.txt
特定目录中的文件,如何在每个文件之前插入文件名作为“中断”?
file #1
contents of file
file #2
contents of file
Run Code Online (Sandbox Code Playgroud)
理想情况下,作为易于记住的几个bash
命令。
也可以看看:
改进的答案;
-exec basename
使用 just-print
将显示文件名,而不是单独的:
find . -type f -print -exec cat {} \;
Run Code Online (Sandbox Code Playgroud)
find . -type f -print -exec cat {} \;
Run Code Online (Sandbox Code Playgroud)
find . -type f -iname '*.txt' -exec basename {} \; -exec cat {} \;
Run Code Online (Sandbox Code Playgroud)
@0stone0 答案的另一种选择您可以使用tail
cat 的 insted:
tail -n +1 *
Run Code Online (Sandbox Code Playgroud)
输出:
==> file-1.txt <==
contents of file
==> file-2.txt <==
contents of file
Run Code Online (Sandbox Code Playgroud)