-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort-pics.sh
More file actions
executable file
·37 lines (33 loc) · 813 Bytes
/
sort-pics.sh
File metadata and controls
executable file
·37 lines (33 loc) · 813 Bytes
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
#!/bin/bash
# Sorts Foscam 8189W IP camera snapshots into directories
# by date and time (hour), e.g. 02-08-2011/03, 02-07-2011/17
# Expected filename format is CAMERAMAC(mymac)_num_timestamp_autoinc-num.jpg
# Author: Nick Davis
for f in *.jpg
do
if [ -f $f ];
then
# split filename and capture timestamp
date=`echo "$f" | awk 'BEGIN {FS="_"}{print $3}'`
# split each field into time periods (year, month, etc.)
y=${date:0:4}
m=${date:4:2}
d=${date:6:2}
h=${date:8:2}
min=${date:10:2}
datedir=$m-$d-$y
# create date dir and hour dir if they don't exist,
# move file to datedir/hourdir
if [ ! -d $datedir ];
then
mkdir $datedir
fi
hourdir="$datedir/$h"
if [ ! -d $hourdir ];
then
mkdir $hourdir
fi
echo "Moving $f to $hourdir"
mv $f $hourdir
fi
done