brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: tail can follow several files at once and label each block

Tail
~/tips/tip-tail-several-files-quiet

tail -f /var/log/nginx/access.log /var/log/nginx/error.log

Watch more than one log in a single terminal window.

Two terminal splits for two logs is fine until there are five of them. One tail command takes a whole list.

tail -f /var/log/nginx/access.log /var/log/nginx/error.log

Output from different files is separated by a header such as ==> error.log <==, printed each time the source changes. Globs work as well:

tail -n 3 -f /var/log/myapp/*.log

The -n 3 keeps the opening burst small when the glob matches many files.

If the headers are in your way, for instance when you pipe into grep, switch them off:

tail -q -f app.log worker.log | grep -i error

And -v does the reverse, printing a header even for a single file, which is nice in a report:

tail -v -n 5 /etc/hostname

I usually start with the headers on to learn which file says what, then filter.

The glob is expanded once, when the command starts. A new log file created later is not picked up, so restart tail after a rotation that makes new names. With -q you can no longer tell which file a line came from. And lines from different files appear in the order tail reads them, which is close to real time but not a reliable ordering for events milliseconds apart.

Further reading: tail invocation

More Tail tips tail -c 2000 export.json tail -f --pid=1234 build.log tail -n +2 export.csv tail -F /var/log/nginx/access.log All Tail tips (5) All topics

Link