blob: e9a66c21851331c3f2d7feea47c76dbb71ba3a13 (
plain)
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
|
#!/bin/bash
#
# Archive dangling files.
#
# Parameters
DATE="`date +%Y%m%d%I%M%S`"
LOAD="$HOME/load"
IMAGES="$HOME/data/images/incoming"
IMAGES_PATTERN=".*\.(png|jpg|jpeg|gif|svg)"
DOC="$HOME/data/doc/incoming"
DOC_PATTERN=".*\.(txt|doc|docx|rtf|pdf|sxc|csv|odt|odf|ods|xls|xlsx|ppt|epub|mobi|djvu|lit)"
NOISE="$HOME/data/noise/incoming"
NOISE_PATTERN=".*\.(mp3|ogg|opus|m4a)"
VIDEO="$HOME/data/video/incoming"
VIDEO_PATTERN=".*\.(mp4|mov|mkv|avi|srt|mpg)"
FIND_OPTS="-maxdepth 1 -regextype posix-egrep -iregex"
# Ensure all folders exist
mkdir -p $LOAD $IMAGES $DOC
# Move images
if [ "`find $LOAD/ $FIND_OPTS "$IMAGES_PATTERN" | wc -l`" != "0" ]; then
echo "Moving images into $IMAGES/$DATE ..."
mkdir -p $IMAGES/$DATE
find $LOAD/ $FIND_OPTS "$IMAGES_PATTERN" -exec mv {} $IMAGES/$DATE/ \;
fi
# Move doc
if [ "`find $LOAD/ $FIND_OPTS "$DOC_PATTERN" | wc -l`" != "0" ]; then
echo "Moving docs into $DOC/$DATE ..."
mkdir -p $DOC/$DATE
find $LOAD/ $FIND_OPTS "$DOC_PATTERN" -exec mv {} $DOC/$DATE/ \;
fi
# Move noise
if [ "`find $LOAD/ $FIND_OPTS "$NOISE_PATTERN" | wc -l`" != "0" ]; then
echo "Moving noise into $NOISE/$DATE ..."
mkdir -p $NOISE/$DATE
find $LOAD/ $FIND_OPTS "$NOISE_PATTERN" -exec mv {} $NOISE/$DATE/ \;
fi
# Move video
if [ "`find $LOAD/ $FIND_OPTS "$VIDEO_PATTERN" | wc -l`" != "0" ]; then
echo "Moving video into $VIDEO/$DATE ..."
mkdir -p $VIDEO/$DATE
find $LOAD/ $FIND_OPTS "$VIDEO_PATTERN" -exec mv {} $VIDEO/$DATE/ \;
fi
|