-
Notifications
You must be signed in to change notification settings - Fork 0
/
task1prgm1.sh
53 lines (44 loc) · 1.27 KB
/
task1prgm1.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
#!/bin/bash
read -p "Enter the path : " r1 # getting the path from the user
echo "$r1"
echo "Names before changing : "
for file in "$r1"/*
do
echo "$(basename $file)" # printing all the files in that folder
done
echo "Names after adding '_New' at the end of all the files and directories : "
for f in "$r1"/*
do
mv "$f" "${f%.*}_New.${f##*.}" # adding _new to all the filenames
done
for f in "$r1"/*
do
echo "$(basename $f)"
done
read -p "Enter the extension of files you want to renmame like .txt, .py : " type
for f in "$r1"/*
do
if [[ "$f" == *"$type" ]] # checking whether the file is having the extension given by the user
then
mv "$f" "${f%.*}_type.${f##*.}" # adding _type to the filenames
fi
done
echo "after adding '_type' at the end of all $type extension file : "
for f in "$r1"/*
do
echo "$(basename $f)"
done
read -p "Enter the extension of the files which you want to change like .txt, .py : " ext1
read -p "Enter the new extension of the file like .txt, .py : " ext2
for f in "$r1"/*
do
if [[ "$f" == *"$ext1" ]] # checking whether the file is having the extension given by the user
then
mv "$f" "${f%.*}${ext2}" # changing the extension
fi
done
echo "after changing the $ext1 extension to $ext2 extension : "
for f in "$r1"/*
do
echo "$(basename $f)"
done