加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 19:47:38 所属栏目:安全 来源:网络整理
导读:参见英文答案 cat multiple files but include filename as headers14个答案在猫的内容之前,找不到打印每个文件名的方法。这里是我想做的: raja@badfox:~/Perl/t$ ls1.txt 2.txt 3.txtraja@badfox:~/Perl/t$ echo " I am " 1.txt raja@badfox:~/Perl/t$ ec
参见英文答案 > 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读