bash – 显示所有文件的内容与他们的文件名与猫

前端之家收集整理的这篇文章主要介绍了bash – 显示所有文件的内容与他们的文件名与猫前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > cat multiple files but include filename as headers14个答案在猫的内容之前,找不到打印每个文件名的方法。这里是我想做的:
raja@badfox:~/Perl/t$ ls
1.txt  2.txt  3.txt
raja@badfox:~/Perl/t$ echo " I am " >> 1.txt 
raja@badfox:~/Perl/t$ echo " trying " >> 2.txt 
raja@badfox:~/Perl/t$ echo " to do this " >> 3.txt 
raja@badfox:~/Perl/t$ cat *.*
 I am 
 trying 
 to do this 
raja@badfox:~/Perl/t$

在最后一个命令中,我只得到这些文件中的文本,但我实际上希望文本与文件名一起。我的意思就是这样

Filename:1.txt 
<Data in the file>

Filename:2.txt 
<Data in that file>

Filename:3.txt
<Data in that file >
猫不会打印文件名。 get the shell to do it或者使用head或tail来代替它们:当您传递多个文件(不完全相同的格式)时,它们会打印文件名称。使用tail -n 1打印整个文件(从第1行开始,行从1编号)。
tail -n +1 -- *.txt
原文链接:https://www.f2er.com/bash/388551.html

猜你在找的Bash相关文章