How to monitor newly created file in a directory with bash?
bash, linux
Solution
First approach - use a hidden file in you dir (in my example it has a name `.watch`). Then you one-liner might look like:
for f in $(find . -type f -newer .watch); do cat $f; done; touch .watch
Second approach - use inotify-tools: https://unix.stackexchange.com/questions/273556/when-a-particular-file-arrives-then-execute-a-procedure-using-shell-script/273563#273563
Problem
I have a log directory that consists of bunch of log files, one log file is created once an system event has happened. I want to write an oneline bash script that always monitors the file list and display the content of the newly created file on the terminal. Here is what it looks like: Currently, all I have is to display the content of the whole directory: ``` for f in *; do cat $f; done ``` It lacks the monitoring feature that I wanted. One limitation of my system is that I do not have `watch` command. I also don't have any package manager to install fancy tools. Raw BSD is all I have. I do have `tail`, I was thinking of something like `tail -F $(ls)` but this tails each file instead of the file list. In summary, I want to modify my script such that I can monitor the content of all newly created files.