-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathlab3-4
executable file
·63 lines (50 loc) · 1.68 KB
/
lab3-4
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
#!/bin/bash
# Wolfgang C. Strack
# CIS18C
# This script is for lab3-4 and copies old files from
# a source directory into a destination directory.
echo "This script copies old files from a source directory to a destination directory."
echo
read -p "Please enter a source directory or hit enter to use current directory: " temp
source=${temp:-'./'}
while [ ! -d $source ] # keep prompting until a valid directory is entered
do
echo "$source is not a directory"
read -p "Please enter a source directory or hit enter to use current directory: " temp
source=${temp:-'.'}
done
echo
read -p "Please enter the destination directory or hit enter to use the directory name \"old\": " temp
destination=${temp:-'./old'}
if [ -d $destination ] # use existing directory or make a new one
then
echo Using existing directory $destination
else
mkdir $destination
echo Using new directory $destination
fi
echo
read -p "In the format mo/dd/yyyy hh:mm, please enter the day and time: " day vtime
epochtime=`date -d "$day $vtime" +%s`
echo
filecount=0
totalfiles=`ls $source | wc -l`
for file in `ls $source` # putting just $source does not seem to iterate through the files
do
filetime=`stat -c %Y $file`
if (( filetime < epochtime )) # if file is older than the time given
then
echo "Copying $file into $destination"
cp -r $file $destination
(( filecount++ ))
fi
done
echo
(( percent = filecount * 100 / totalfiles ))
echo "$filecount files copied out of $totalfiles: $percent%"
# echo "Files in source directory:"
# ls $source
# read -p "Please choose a file: " filechosen
# stat -c "Epoch time for $filechosen: +%Y seconds" $filechosen
# echo "Copying $filechosen into $destination"
# cp $filechosen $destination