-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoen.sh
102 lines (88 loc) · 2.04 KB
/
voen.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /bin/bash
identify_interpritator (){
filename=$1
firstline=$(head -n 1 $filename)
start=${firstline:0:2}
if [[ $start == "#!" ]]
then
inter=${firstline#*bin/}
ind=`expr index "$inter" " -"`
if [[ $ind > 0 ]]
then
let ind=ind-1
res=${inter:0:$ind}
echo "$res ---> $filename"
mv "$filename" "${filename%.*}.${res}" # rename file
let map[$res]+=1
else
echo "$inter ---> $filename"
mv "$filename" "${filename%.*}.${inter}" # rename file
let map[$inter]+=1
fi
else
echo "Bad file---> $filename"
let map[bad]+=1
#`rm $filename`
fi
}
a=( `find /usr/bin -type f -perm /111` )
a+=( `find /bin -type f -perm /111` )
#if ~/bin exist then remove it
if [ -d ~/bin/ ]; then
`rm -rf ~/bin`
fi
`mkdir ~/bin`
declare -A map # associative array
for ((i=0; i <${#a[@]} ; i++))
do
#echo "${a[$i]}"
`cp ${a[$i]} ~/bin`
#identify_interpritator ${a[$i]}
done
#now working with copies of files
b=( `find * ~/bin -type f -perm /111` )
for ((i=0; i <${#b[@]} ; i++))
do
identify_interpritator ${b[$i]}
done
#show how much different files we have
echo "We have files of following types:"
for i in "${!map[@]}"; do
echo "$i : ${map[$i]}"
done
#---------------------------------------------------
# which files we should save?
declare -a safe # array of choosed files
echo "Вводите через ENTER расширения файлов, которые хотите оставить"
echo "Введите stop для завершения ввода расширений"
while true
do
read m
if [[ "$m" == "stop" ]]
then
break
fi
safe+=( $m )
done
echo "Вы выбрали:"
for ((i=0; i <${#safe[@]} ; i++)); do
echo "${safe[$i]}"
done
#------------------------------------------------------
# delete unlucky files
for f in $b; do
end=${f#*.}
for target in "${safe[@]}"; do
if [[ $end == "$target" ]]; then
for target in "${safe[@]}"; do
for i in "${!map[@]}"; do
if [[ ${i} = "$target" ]]; then
unset ${map[i]}
fi
done
done
#what in map now?
echo "what in map now?"
for i in "${!map[@]}"; do
echo "$i : ${map[$i]}"
done