Created
October 23, 2014 08:39
-
-
Save camsaul/fdfa44aacfcd7340c4b4 to your computer and use it in GitHub Desktop.
Bash function to get the date a file is modified, works for BSD or Linux
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
#!/bin/bash | |
# return unix timestamp for file or 0 if it doesn't exist | |
[ `uname` == "Darwin" ] && STAT_FORMAT_FLAG='-f' || STAT_FORMAT_FLAG='-c' | |
file_modified () { | |
file=$1 | |
if [ -f "$file" ] && [ -n "$file" ]; then # make sure filename is non-empty, -f will return true otherwise | |
echo `stat $STAT_FORMAT_FLAG "%a" $file` | |
else | |
echo "0"; | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment