0

As far as I know, tail -f <filename> allows to continuously print newly appended data from one single file.

What if I need to get content from multiple files located in multiple folders under the same parent folder, then filter that content if need be, and finally print it as a real-time stream, as new data gets appended to any one of the multiple monitored files?

EDIT: the operating system is RedHat Enterprise Linux 7.4

KiriSakow
  • 105

2 Answers2

0

Use the following oneliner:

while true; do cat /path/to/numerous/folders/and/files/*/*.txt | grep "some filter" | tail -n 10; sleep 1; done

Every 1 second, the script will print 10 last lines of the filtered stream.

To break the loop, press CtrlC.

KiriSakow
  • 105
  • Is this really what you wanted? Unlike tail -f, it will repeat the same lines over and over if there is no change, and can miss lines if more than 10 lines are added to a file in the 1-second window. – n.st Dec 04 '18 at 23:18
  • @n.st This oneliner did the job pretty well so far. At least for the time being. – KiriSakow Dec 04 '18 at 23:43
-1

Try this command:

ls /path/to/files/to/be/monitored/by/tail | while read fname; do tail -f $fname & done; wait
Chris Davies
  • 116,213
  • 16
  • 160
  • 287