Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer
hey thanks! It works but the problem i have is that it orders the files alphabetically instead of numerically. For example, the list log.1, log.2, log.10 is sorted as log.1, log.10, log.2 and not as log.1, log.2, log.10. Is there any trick for this?! – Kostas May 10 '10 at 10:25
@Kostas: If there are no spaces, etc., in the filenames, you could do something like find . -maxdepth 1 -name "log.*" | sort -V | less for "one big file" or for a sequence of files: less $(find . -maxdepth 1 -name "log.*" | sort -V). – Dennis Williamson May 10 '10 at 10:39
It seems that the "-V" parameter is not available on my machine. Here are the available options: -b -d -f -g -i -M -n -r -c -k -m -o -s -S -t -T -u -z. – Kostas May 10 '10 at 10:57
This is what I have come up with: less -M -e allocation-engine.log allocation-engine.log.? allocation-engine.log.??. Its not the best solution but it will work for most cases! Thanks again! – Kostas May 10 '10 at 11:06
@Kostas: This might work to sort your files numerically since your sort doesn't have --version-sort (-V): find -maxdepth 1 -type f -name "allocation-engine.log*" | while read -r file; do num="${file##*.}"; if [[ $num == ${file#*.} ]]; then num=''; fi; printf "%03d %s\n" "$num" "$file"; done | sort | cut -d ' ' -f2 – Dennis Williamson May 10 '10 at 13:40


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.