-
Notifications
You must be signed in to change notification settings - Fork 3
/
untouched
executable file
·58 lines (46 loc) · 1.19 KB
/
untouched
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
################################################################################
# untouched - determines whether or not a directory has been changed in the
# last N days. All subdirectories and files within the directory are considered.
#
# Version 1
# Matthew Malensek <[email protected]>
################################################################################
verbose=false
print_usage() {
cat <<EOM
Usage: $(basename ${0}) [-v] dir num_days
Determines whether the contents of 'dir' have changed in the last 'num_days'
days.
Additional options:
-v Verbose mode. Files and directories that have changed are printed.
Returns:
zero if no changes were found, nonzero otherwise.
EOM
}
while getopts "v" flag; do
case ${flag} in
v) verbose=true ;;
?) print_usage; exit 1 ;;
esac
done
shift $(($OPTIND - 1))
if [[ ${#} -ne 2 ]]; then
print_usage
exit 1
fi
dir=${1}
days=${2}
if [[ ! -d "${dir}" ]]; then
>&2 echo "Directory not found: ${dir}"
exit 1
fi
changed=$(find "${dir}" -ctime -"${days}")
if [[ "${changed}" == "" ]]; then
exit 0
else
if [[ ${verbose} == true ]]; then
echo "${changed}"
fi
exit 1;
fi