Issue
I want to be able to :
- concatenate all files in a directory (regular and hidden),
- but I would also like to display the title of each file at the beginning of each concatenation.
I found some solutions on the web, where I can do #2 with tail -n +1 * 2>/dev/null
super neat trick, but it doesn't include hidden files like if I were to do: cat * .* 2>/dev/null
or even head * .* 2>/dev/null
The cat command will do the trick but doesn't include the filename, and the head command will not print/concatenate the whole contents of each file.
Question
Is there a way to do what I need to do with tail
, if not what is a good substitute to achieve the same result/output.
Update with an example
The tail command when attempting to concatenate all files (regular and hidden)
[kevin@PC-Fedora tmp]$ ls -la
total 8
drwx------ 2 user user 4096 Jun 23 09:24 .
drwxr-xr-x. 54 user user 4096 Jun 23 08:21 ..
-rw-rw-r-- 1 user user 0 Jun 23 09:24 .f1
-rw-rw-r-- 1 user user 0 Jun 23 09:24 f1
-rw-rw-r-- 1 user user 0 Jun 23 09:24 .f2
-rw-rw-r-- 1 user user 0 Jun 23 09:24 f2
-rw-rw-r-- 1 user user 0 Jun 23 09:24 .f3
-rw-rw-r-- 1 user user 0 Jun 23 09:24 f3
-rw-rw-r-- 1 user user 0 Jun 23 09:24 .f4
-rw-rw-r-- 1 user user 0 Jun 23 09:24 f4
-rw-rw-r-- 1 user user 0 Jun 23 09:24 f5
[user@PC-Fedora tmp]$ tail -n +1 *
==> f1 <==
==> f2 <==
==> f3 <==
==> f4 <==
==> f5 <==
[user@PC-Fedora tmp]$ tail -n +1 * .*
==> f1 <==
==> f2 <==
==> f3 <==
==> f4 <==
==> f5 <==
==> . <==
tail: error reading '.': Is a directory
[user@PC-Fedora tmp]$
tail -n +1 * .*
? You've tried that with bothhead
andcat
, why nottail
? Is it that you sometimes only have one file so you don't get the file name? – terdon Jun 23 '21 at 16:23tail -n +1 * .[^.]*
, which is basically explained in the suggested duplicate. If that works for you, please accept the duplicate suggestion. – terdon Jun 23 '21 at 16:32head
andtail
process arguments is different, hence.[^.]*
regex is needed to match hidden files. – 0x5929 Jun 23 '21 at 16:48