-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdel_ext
More file actions
executable file
·48 lines (39 loc) · 1.01 KB
/
del_ext
File metadata and controls
executable file
·48 lines (39 loc) · 1.01 KB
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
#!/bin/bash
# Delete all files having a specific extension according to the existing files having another specific extension
# For example: "del_ext mp3 ogg" will delete MP3 files if an OGG file with the same name exists in the same directory
function confirm()
{
echo -n "$@ "
read -e answer
for response in y Y yes YES o oui O
do
if [ "_$answer" == "_$response" ]
then
return 0
fi
done
# Any answer other than the list above is considerred a "no" answer
return 1
}
if [[ $# -lt 2 ]]; then
echo "Usage: $0 [extension to be deleted] [reference extension]"
exit
fi
ref=$2
del=$1
echo "Delete all .$del if a $ref. of the same name exists"
confirm "OK?"
if [ $? -eq 1 ]
then
exit
fi
echo ""
find . -maxdepth 1 -type f -iname "*.$ref" -print0 | while IFS= read -r -d $'\0' line; do
toDel=${line/.$ref/.$del}
echo "Reference file : $line"
ls -l "$line"
echo "File to delete : $toDel"
ls -l "$toDel"
rm -v "$toDel"
echo ""
done