-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdel.sh
58 lines (42 loc) · 965 Bytes
/
sdel.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
#!/bin/bash
#echo $USER
MyTrash=/home/$USER/TRASH/
#Check if the Trach already exist or Not
if ! [ -d "$TRASH" ]
then
mkdir $MyTrash
fi
# $# : returnnumber of arguments
#First Case The User Did not write any files
if [ $# -eq 0 ]
then
echo Take Care You Did not pass Any File To compress and move it to TRASH
echo So You Must Write Files you want to compress and move to TRASH
echo For Example: ./sdel.sh [file1] [file2] ... [fileN]
fi
#Second Case
for i in $*
do
if [ -f "$i" ]
then
if !(file $i | grep -q compressed )
then
tar czf $i.tar.gz $i
sudo mv $i.tar.gz $MyTrash
else
echo "$i is Compressed"
sudo mv $i $MyTrash
fi
else
echo "$i is not exist! .. No such File !!"
fi
done
result=$(find $MyTrash -name "*" -type f -atime +2)
if [ -z "$result" ]
then
echo 'There Are No Files In Trach for more Than 48 h'
else
echo "$result"
echo 'Were In Trach for more Than 48 h and Deleted'
find $MyTrash -name "*" -type f -atime +2 -delete
fi