Search code examples
linuxpipecatlsxargs

how to pipe ls into cat with xargs so that filenames are listed?


For using cat to output *.txt files within a specific directory, how can I insert the filename as a "break" before each file?

file #1
contents of file

file #2
contents of file

ideally as an easy to remember few bash commands.

see also:

Why not pipe list of file names into cat?


Solution

  • One more option to @0stone0 answer You can use tail insted of cat:

    tail -n +1 *
    

    Output:

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