fswatch的使用

fswatch -0 -x -r -e /Users/wish/_data/webpage/.DS_Store /Users/wish/_data/webpage/| xargs -0 -n1 -I {} /Users/wish/bin/ftp_upload/ftpupload.sh "{}"

fswatch -0 ~/motion-detection | xargs -0 -n1 -I {} ./detectmotion.sh "{}"

Fetching Title#fo66

fswatch --batch-marker=EOF -xn . | while read file event; do 
   echo $file $event
   if [ $file = "EOF" ]; then 
      echo TRIGGER
   fi
done

If you want to save the names of the affected files in a list, you can do that like this:

#!/bin/bash
fswatch --batch-marker=EOF -xn . | while read file event; do
    if [ $file = "EOF" ]; then
       echo TRIGGER
       echo Files: "${list[@]}"
       list=()
    else
       echo $file $event
       list+=($file)
    fi
done

linux - How to print file path that caused fswatch to do something - Stack Overflow

#!/bin/bash

# Usage:
# file-event-watch command-to-run path1 [path2, ...]
# TODO: Add fswatch event option to enable/disable different event types

cmd=$1
shift
files=$@
$cmd && fswatch -0 -x -r $files | {
  while read -d "" event; do
    case $event in
      *Created|*Updated|*Removed|*Renamed|*OwnerModified|*AttributeModified|*MovedFrom|*MovedTo )
        # https://github.com/emcrisostomo/fswatch/blob/master/src/fswatch.cpp
        # If it's one of these events, run cmd, else ignore it
        $cmd
        ;;
    esac
  done
}

Filter fswatch events by type · GitHub