-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclean-files.sh
More file actions
58 lines (50 loc) · 727 Bytes
/
clean-files.sh
File metadata and controls
58 lines (50 loc) · 727 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
usage()
{
cat << EOF
usage $0 options
OPTIONS
-p path to files to be deleted
-d number of days older files
EOF
}
path=''
numberofdays=''
if [ $# -eq 0 ];
then
usage
exit 1
fi
while getopts "hp:d:" opt
do
case $opt in
h)
usage
exit 1
;;
p)
echo "Path : $OPTARG"
path=$OPTARG
;;
d)
echo "Number of days : $OPTARG"
numberofdays=$OPTARG
;;
\?)
echo "Invalid option: $OPTARG" >&2
usage
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
exit 1
;;
esac
done
if [ ! -z $path ] && [ ! -z $numberofdays ];
then
find ${path}/* -mtime +${numberofdays} -exec rm {} \;
echo "Cleaned the files..!"
exit 1
fi