No idea about a shell solution, but (assuming Linux1
) inotify
could be the way to go... see this example imitating tail -F
(using pyinotify
), maybe it can be used as a basis for following an entire directory.
In general, inotify
can monitor directories (citing man 7 inotify
)
The following bits can be specified in mask
when calling inotify_add_watch(2) and may be returned in the mask field
returned by read(2):
IN_ACCESS File was accessed (read) (*).
IN_ATTRIB Metadata changed, e.g., permissions, timestamps,
extended attributes, link count (since Linux 2.6.25),
UID, GID, etc. (*).
IN_CLOSE_WRITE File opened for writing was closed (*).
IN_CLOSE_NOWRITE File not opened for writing was closed (*).
IN_CREATE File/directory created in watched directory (*).
IN_DELETE File/directory deleted from watched directory (*).
IN_DELETE_SELF Watched file/directory was itself deleted.
IN_MODIFY File was modified (*).
IN_MOVE_SELF Watched file/directory was itself moved.
IN_MOVED_FROM File moved out of watched directory (*).
IN_MOVED_TO File moved into watched directory (*).
IN_OPEN File was opened (*).
When monitoring a directory, the events marked with an asterisk (*) above can
occur for files in the directory, in which case the name field in the returned
inotify_event structure identifies the name of the file within the directory.
(...and pyinotify
closely follows theses options)
1
: BSDs have a similar thing, kqueue
. Maybe a cross-platform solution is achievable using GIO (Python bindings) as abstraction layer since it can, beside inotify
, also use kqueue
tail
-- without any of the ncurses control. I.e., so I could just scroll upwards like normally and see the prior contents. In my use case, I don't care which file the output is coming from. But I do want to easily scroll back upwards. I'm currently using a commandmultitail -d -Q 1 'directory/*'
but don't get any scrolling upwards. – Chris Prince Jul 25 '20 at 23:47