How to view multiple log files as one file in unix/linux

log-filesunix

I was wondering if there is a convenient way in linux/unix to read multiple log files as one.

More specifically, I would like to view a sequence of log files (app.log, app.log.1 app.log.2, etc) as one big file using normal unix tools (vi, less, etc). When the EOF is read the tool will automatically move to the beginning of the next file.

During my work I have to analyze uat/prod logs to investigate and solve problems. The fact that I need to traverse many log files disturbs my work and causes delays.

Any ideas?

Best Answer

You can use lists of files and file globbing to specify multiple files.

One big file:

cat file1 file2 anotherbunch* log[a-z] | less

A sequence of files (type :n to go to the next one):

less -e file1 file2 anotherbunch* log[a-z]

The -e switches to the next file automatically when the end of the current file is reached (twice) and exits when the end of the last file is reached (twice). To do that on the first time EOF is reached, use the -E option.