Skip to content

Instantly share code, notes, and snippets.

@simbalinux
Created July 13, 2018 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simbalinux/4e1eab41e4f83de1fd63a9102e54cc00 to your computer and use it in GitHub Desktop.
Save simbalinux/4e1eab41e4f83de1fd63a9102e54cc00 to your computer and use it in GitHub Desktop.
stat compare on directory
#!/usr/bin/env bash
DIR_TO_CHECK='./'
OLD_STAT_FILE='./old_stat.txt'
if [ -e $OLD_STAT_FILE ]
then
OLD_STAT=$(cat $OLD_STAT_FILE)
else
OLD_STAT="nothing"
fi
NEW_STAT=$(stat -t $DIR_TO_CHECK)
if [ "$OLD_STAT" != "$NEW_STAT" ]
then
echo 'Directory has changed. Do something!'
# do whatever you want to do with the directory.
# update the OLD_STAT_FILE
echo $NEW_STAT > $OLD_STAT_FILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment