1

This question already has an answer here:

I am working with a directory where logs are constantly created. I use tail -f * in bash to view all the log entrys in the dir. However, when new files are created while the tail is running, the new files are not utilized by the tail. Is there a simple solution for that? Thank you!

EDIT: OS: SLES4SAP 12 SP2 3.0.101-63-default

marked as duplicate by Stephen Kitt, Jeff Schaller, Archemar, roaima, meuh Feb 20 '18 at 14:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Ugh, that linked "duplicate" question is terrible. Nowhere does it state that the list of files is changing. – Patrick Feb 20 '18 at 14:45
1

When you execute the tail -f * command it expands * to the files present in the directory in that moment, so when a new file is added to it you won't be able to see it unless you use tail again and add the new file to the arguments.

You could use watch with tail so it's always expanding * and if a new file appears it'll be matched.

An example would be watch -n 1 tail *, then you can adjust the update interval as you need, depending on the update rate of your log files.

  • I wouldn't use watch for that, but you're not too far off the right track. Better would be a shell script that runs tail -f * (or one tail -f for each file in the directory if you want to be able to stop tailing a file if it is closed or deleted) and then uses inotify to monitor the directory. As new files are created, fork another tail for them. And (optionally) if a file is closed or deleted, kill the corresponding tail process. Alternatively, a perl script using File::Tail and Linux::Inotify2. hmmm...it turns out that the (perl) utility iWatch does stuff like that. – cas Feb 21 '18 at 1:50
  • 1
    see iwatch.sourceforge.net (or apt-get install iwatch on debian etc) – cas Feb 21 '18 at 1:52

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