-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfindbydate
More file actions
executable file
·87 lines (71 loc) · 1.17 KB
/
findbydate
File metadata and controls
executable file
·87 lines (71 loc) · 1.17 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
#
# findbydate
#
[ -n "$MYDIR" ] || {
declare MYDIR=
MYDIR="$(dirname "$(readlink -f "$0")")"
}
declare optcount=0
declare date
declare depth=0
declare usagestr=
usagestr=$(
cat <<EOF
$(basename "$0") [options] date
Arguments
---------
date : formatted as "yyyy-mm-dd"
Options
-------
o:file : Optional output file
d:depth : Recursion depth. Minimum is 0 to include the currend dir.
\0
EOF
)
# control_c: run if user hits control-c
#
# Global
# CTLC_EXIT - bash environment variable
#
control_c() {
echo -e "\nCtrl-c detected\nCleaning up and exiting."
exit $CTLC_EXIT
}
# parseopts
#
# Globals
#
parseopts() {
local arg=
local opt=
for arg in $@; do
if [ "${arg:0:1}" == "-" ]; then
opt="${arg:1}"
shift
((optcount++))
case "$opt" in
o ) file=$1
shift
((optcount++))
;;
d ) depth=$1
shift
((optcount++))
;;
h ) echo -e "$usagestr"
exit 0
esac
fi
done
}
main() {
local out="/dev/stdout"
parseopts "$@"
shift "$optcount"
date="$1"
[ -n "$file" ] && { out="$file"; :> "$out"; }
find . -mindepth $depth -type f -newermt "$date" -exec ls -1t {} + > "$out"
exit 0
}
main "$@"