Created
July 13, 2018 17:19
-
-
Save simbalinux/4e1eab41e4f83de1fd63a9102e54cc00 to your computer and use it in GitHub Desktop.
stat compare on directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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