Created
September 27, 2016 16:50
-
-
Save Vultour/75809ddafd796d023a933197f59ce0ab to your computer and use it in GitHub Desktop.
Time-specific find
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 | |
USAGE="Usage: $0 <FOLDER> <ORIGIN-FILE> <TIME-LIMIT> [RECURSIVE?]" | |
if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then | |
echo $USAGE | |
exit 1 | |
fi | |
DIR=$1 | |
ORG="$(date --date "$(stat $2 | grep -E 'Modify: (.*)$' | grep -oE '[0-9]+.*')" +"%s")" | |
LIM=$3 | |
REC="" | |
if [ -z $4 ]; then | |
REC="-maxdepth 1" | |
fi | |
if [ ! -d $DIR ]; then | |
echo "Error: directory '$DIR' doesn't exist" | |
fi | |
echo "Origin: $ORG" | |
for item in $(find $DIR $REC); do | |
FILE=$item | |
TIMESTAMP="$(date --date "$(stat $FILE | grep -E 'Modify: (.*)$' | grep -oE '[0-9]+.*')" +"%s")" | |
if [ $LIM -gt 0 ]; then | |
CHECK=$(($ORG + $LIM)) | |
if [ $TIMESTAMP -lt $CHECK ] && [ $TIMESTAMP -gt $ORG ]; then | |
echo $FILE | |
fi | |
fi | |
if [ $LIM -lt 0 ]; then | |
CHECK=$(($ORG $LIM)) | |
if [ $TIMESTAMP -gt $CHECK ] && [ $TIMESTAMP -lt $ORG ]; then | |
echo $FILE | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment