I see in the documents for fswatch it has $ fswatch -0 [opts] [paths] | xargs -0 -n 1 -I {} [command]
but I don't really understand how I'm supposed to add multiple paths to that - I'm watching two paths lib
and test
. I've tried:
fswatch -r lib,test
, fswatch -r lib test
, and finally fswatch -r [lib test]
How do I watch multiple paths with fswatch at the same time?
Asked
Active
Viewed 1,743 times
3

Jono
- 3,393
- 6
- 33
- 48
3 Answers
4
Separate the paths with a space (i.e. ' ')
For example:
fswatch "path/one" "path/two" echo "whatever"

Alan W. Smith
- 24,647
- 4
- 70
- 96

mikhuang
- 2,694
- 2
- 19
- 17
-
1This works perfectly! But then how do you know which one changed? – Nathan Arthur Feb 21 '17 at 17:31
1
The only possibility I found is to execute the fswatch
command multiple times:
do_backup() {
// what you want to do
rsync -ahhvzPR --delete $FILE $BACKUP_DIR
}
fswatch -r lib | while read FILE; do
do_backup
done &
fswatch -r test | while read FILE; do
do_backup
done &
This will start the process for both directories in detached mode.
More about the detached mode can be found here.