-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_year.sh
executable file
·60 lines (47 loc) · 1.33 KB
/
sort_year.sh
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
#!/bin/sh
PATH=/bin:/usr/bin/:/usr/sbin/; export PATH
if [ $# -lt 1 ] ; then
echo "$0 Error: Not enough arguments" >&2
exit 1
fi
#check the number of arguments
if [ $# -eq 1 ] || [ $# -gt 1 ] ; then
args=("$@")
for i in "$@" ; do
echo $i
#check if an argument isn't a file.
if [ ! -e "$i" ] ; then
echo "$0 Error: \""$i"\" is not a file or a directory" >&2
#if its a directory, check the files within and move them.
elif [ -d "$i" ] ; then
echo "$0 Info: \""$i"\" is a directory, moving internal files"
#file=("$(find $i -type f)")
for j in "$i"/* ; do
echo "$j"
date=$(stat "$j" | grep Modify | awk '{ print $2 }' | awk -F- '{print $1}')
echo $date
#check if there is not a directory for that year
if [ ! -d $date ] ; then
echo "$date doesn't exist. creating..."
mkdir ./$date
fi
echo "second loop"
cp -pr "$j" ./$date
done;
else
echo $i
#echo good
#get the date the file was modified and set the var to it.
date=$(stat "$i" | grep Modify | awk '{ print $2 }' | awk -F- '{print $1}')
echo $date
#check if there is not a directory for that year
if [ ! -d $date ] ; then
echo "$date doesn't exist. creating..."
mkdir ./$date
fi
cp -pr "$i" ./$date
fi
#sleep 1
done
fi
#stat * | grep Modify | awk '{ print $2 }' | awk -F- '{print $1}'