How to rename all the files in a folder having specific
extension?
Example: I have some files with extension (.txt) in a folder
name 'Test'. I have to rename all the .txt files in a test
and its subdirectories to .my extension.
Answer Posted / vipin
The script given below may work properly.
find command is used to search in all the subdirectories.
basename will extract only filename with .txt extension from
absolute path of file.
cut command will print opnly filename without extension.
mv command is uset to rename.
#!/bin/bash
for i in $(find -name \*.txt)
do
mv $i $(echo `basename $i` | cut -d . -f 1).my
done
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
Which shell is the best?
How do scripts work?
What does echo $0 do?
I want to create a directory such that anyone in the group can create a file and access any person's file in it but none should be able to delete a file other than the one created by himself.
What is ms powershell?
Explore about environment variables?
What are the two files of crontab command?
How do I open the shell prompt?
How to check if the previous command was run successfully?
What is the difference between bash and shell?
Which scripting language is best for automation?
How does ls command work?
What is bash coding?
madhar chod unix ke 10 commands dhang se likh nahi sakta hai
How can you find out how long the system has been running?