Skip to content

Instantly share code, notes, and snippets.

@TheYarin
Created January 13, 2019 17:27
Show Gist options
  • Save TheYarin/f8c7528adfb8804593ee73634ae9ad76 to your computer and use it in GitHub Desktop.
Save TheYarin/f8c7528adfb8804593ee73634ae9ad76 to your computer and use it in GitHub Desktop.
Clear a folder when it is "created". For example, when a flash drive is connected and mounted to /path/to/containing/folder, clear the folder inside of it named FOLDER_NAME
inotifywait -mq --format '%w%f/FOLDER_NAME/' --event=CREATE /path/to/containing/folder | while read DIR_TO_CLEAR
do
echo "$DIR_TO_CLEAR"
sleep 1
find "$DIR_TO_CLEAR" -delete
mkdir -p "$DIR_TO_CLEAR"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment