List content of one or more files with a header showing the file name

后端 未结 1 1194
太阳男子
太阳男子 2021-01-26 01:10

Sometime ago I read a blog that showed a misuse of a commandline command that when given a list of files serially showed the content of each file and each file had head

相关标签:
1条回答
  • 2021-01-26 01:42

    You can use either tail or head for this: when given multiple files, both tools precede each file's contents with a header containing the file name.

    $ for i in {1..3}; do echo line$i > file$i; done
    $ tail file*
    ==> file1 <==
    line1
    
    ==> file2 <==
    line2
    
    ==> file3 <==
    line3
    

    To output the entire files instead of just the last/first 10 lines of each, use tail -n +1 or head -n -0.

    0 讨论(0)
提交回复
热议问题