So I know you can exclude files from being watched but what about the other way ? What if I only want to watch *.txt only ?
Asked
Active
Viewed 1,514 times
1 Answers
3
Just pass the names you want to watch as arguments:
intotifywait ... *.txt
If you are concerned the pattern will match too many files to fit on the command line, you can use the --fromfile
arguments to read the list of files to monitor from a file. The file needs to contain the actual file names, not a pattern, so you might need to create the file with something like
for f in *.txt; do printf '%s\n' "$f"; done > files.txt
inotifywait --fromfile files.txt ...

chepner
- 497,756
- 71
- 530
- 681
-
the command seems to work only if a txt file exists but the directory might be empty in my case and I want it to keep runnin in a while loop – blank_sam Sep 29 '16 at 18:26
-
In that case, you aren't really watching the files, but rather the directory itself. – chepner Sep 29 '16 at 18:28