Just as another idea, try tail -n +1 ./tmp/*.txt
==> ./tmp/file1.txt <==
<contents of file1.txt>
==> ./tmp/file2.txt <==
<contents of file2.txt>
==> ./tmp/file3.txt <==
<contents of file3.txt>
Answer from Random832 on Stack ExchangeJust as another idea, try tail -n +1 ./tmp/*.txt
==> ./tmp/file1.txt <==
<contents of file1.txt>
==> ./tmp/file2.txt <==
<contents of file2.txt>
==> ./tmp/file3.txt <==
<contents of file3.txt>
$ for file in ./tmp/*.txt; do printf '%s\n' "$file"; cat "$file"; done
-or-
$ find ./tmp -maxdepth 1 -name "*.txt" -print -exec cat "{}" \;
cat file
The cat program will open, read and close the file.
cat < file
Your shell will open the file and connect the contents to cat's stdin. cat recognizes it has no file arguments, and will read from stdin.
There is no difference from a user point of view. These commands do the same thing.
Technically the difference is in what program opens the file: the cat program or the shell that runs it. Redirections are set up by the shell, before it runs a command.
(So in some other commands--that is, not the command shown in the question--there may be a difference. In particular, if you can't access file.txt but the root user can, then sudo cat file.txt works but sudo cat < file.txt does not.)
You can use either one that is convenient in your case.
There are almost always many ways to get the same result.
cat accepts a file from arguments or stdin if there are no arguments.
See man cat:
SYNOPSIS
cat [OPTION]... [FILE]...
DESCRIPTION
Concatenate FILE(s) to standard output.
With no FILE, or when FILE is -, read standard input.
Videos
Was looking for the same thing, and found this to suggest:
tail -n +1 file1.txt file2.txt file3.txt
Output:
==> file1.txt <==
<contents of file1.txt>
==> file2.txt <==
<contents of file2.txt>
==> file3.txt <==
<contents of file3.txt>
If there is only a single file then the header will not be printed. If using GNU utils, you can use -v to always print a header.
I used grep for something similar:
grep "" *.txt
It does not give you a 'header', but prefixes every line with the filename.
Just as another idea, try tail -n +1 ./tmp/*.txt
==> ./tmp/file1.txt <==
<contents of file1.txt>
==> ./tmp/file2.txt <==
<contents of file2.txt>
==> ./tmp/file3.txt <==
<contents of file3.txt>
$ for file in ./tmp/*.txt; do printf '%s\n' "$file"; cat "$file"; done
-or-
$ find ./tmp -maxdepth 1 -name "*.txt" -print -exec cat "{}" \;