Show contents of many files

command linefiles

From the command line, what is the easiest way to show the contents of multiple files? My directory looks like below.

./WtCgikkCFHmmuXQXp0FkZjVrnJSU64Jb9WSyZ52b
./xdIwVHnHY7dnuM9zcPDYQGZFdoVORPyMVD2IzjgM
./GZnATXO1e5Hh3Bz1bhgJjjwheIjjZqtnXR0hfOyj
./mWz7ehBNoTZmtDh8JG6sxw2lMJFwIovPzxDGECUY
./JN65F5v3RL2ilHPqNSx9N9D4lvVpqpbJ9lASd8TJ
./At9PS4y4nTiXUO0Z0USnbYkTPBla1msQRpwuruqE
./YiPyMZPCaUDZTiTczAvWII9bJrUqLXCFtH2pXEA2
./JoakdlbRFPwAvWp1d4n8RvMoyMeizCoiriL2Sn2U
./wFPWZUus8Yu7UtESGABLCoqDg36cT90USO0xuyUr
./qseI9PgV1EJfZCDyGGeVytajqG7JeX0r7eA5S1JW
./zgFJpNgXyCsaVh38aCuMGuzHwIbwSNB6rQDdh27x
./.htaccess

Now I'd like to view the contents of all files except .htaccess. It might look something like:

WtCgikkCFHmmuXQXp0FkZjVrnJSU64Jb9WSyZ52b:
Contents of file WtCgikkCFHmmuXQXp0FkZjVrnJSU64Jb9WSyZ52b.

xdIwVHnHY7dnuM9zcPDYQGZFdoVORPyMVD2IzjgM:
Contents of file xdIwVHnHY7dnuM9zcPDYQGZFdoVORPyMVD2IzjgM.

[...]

I think this should be doable with a combination of find, xargs and cat, but I haven't figured out how. Thanks for your time!

Best Answer

The two standard commands head and tail print a header with the file name if you pass them more than one file argument. To print the whole file, use tail -n +1 (print from the first line onwards, i.e. everything).

Here, it looks like you want to see every file except the single one whose name begins with a dot. Dot files are “hidden” under unix: they don't appear in the default output of ls or in a wildcard match. So matching every non-hidden files is done with just *.

tail -n +1 *

(Strictly speaking, tail -n +1 -- * is needed in case one of the file names begins with a -.)

Related Question