If all files exist and you have a modern tail implementation that can handle multiple files,
tail -f *.out
would seem like a better solution. But if you donβt have all the files to start with, then it would still be easier if you just created them. *.out will only expand to files that you already have.
But if you cannot know the file names for tail -f before you start, you will need to restart the tail if any new files are created during your tail. In this case, given that you only write each outfile one at a time, you can do:
inotifywait -m -e create -q . | while read dir event file; do kill %tail tail -f "$file" & done kill %tail
(This requires inotifywait , which is included with inotify-tools on Debian-based systems such as Ubuntu.) It tracks the current directory for newly created files, tails depending on which file was created, in the background and kills the previous command tail whenever a new file is created.
source share