Since the rename
command didn't work for me for unknown reasons and i do not get any other answers for my question, i myself tried to make an effort to make the rename possible. This might not be the best approach to rename the files but it worked for me and this is why i would like to post it as an answer so that if anyone else reads this might get some help to change the file names the way i did.
Now for me, i know that all the files will have a specific text in their names which is the word "Block". Following are the file names before their renaming was done:
anks@anks:~/anks$ ls -lrt
total 4
-rw-r--r-- 1 anks anks 0 Jul 25 14:47 Bharti TRX Block [email protected]
-rw-r--r-- 1 anks anks 0 Jul 25 14:47 Bharti TRX Block [email protected]
-rw-r--r-- 1 anks anks 0 Jul 25 14:47 Bharti TRX Block [email protected]
-rw-r--r-- 1 anks anks 0 Jul 25 14:47 Bharti TRX Block [email protected]
-rw-r--r-- 1 anks anks 0 Jul 25 14:48 Bharti TRX Block [email protected]
Now i have written a small shell script to make this possible. Following is the code:
#!/bin/bash
PATH="/home/ebfijjk/anks"
# Put the old filenames in a file.
ls $PATH | grep Block >> oldValues
# Put the new names without " " or "@" or "$" in another file
cat oldValues | sed 's/\$/_/g' | sed 's/\@/_/g' | sed 's/ /_/g' >> newValues
# Create a new file with Old names and New names seperated by a #.
paste -d'#' oldValues newValues >> oldAndNew
# Read the file with both old and new names and rename them with the new names.
while IFS='#'; read oldValue newValue
do
mv "$oldValue" "$newValue"
done < oldAndNew
rm oldValues newValues oldandNew
And that's it, when i run the script, it renames all the file names having blank spaces (
) or $
or @
with _
instead of these characters.