Watch Multiple Files Simultaneously

[problem]

Performing debugging and you need to view the output, of more than one file at once.

[/problem]

[solution]

A simple way to keep an eye on a file is with tail.


tail -f logfile

You can background this, by appending an ampersand:


tail -f logfile&

[/solution]

[example]

But if you want to watch multiple files, how do you know which one received the update.

Sed to the rescue:


tail -f logfilea | sed 's/^/logfilea: /'&
tail -f logfileb | sed 's/^/logfileb: /'&

[/example]

[reference]

[tags], Unix Coding School[/tags]

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *