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
Why is a script important?
What are the advantages of shell scripting?
Explain about sourcing commands?
What is the default shell of solaris?
write a shell script to generate a alert ? like when ur birthday came then generate a alert ur birthday is today like that ?
What is the equivalent of a file shortcut that we have a window on a linux system?
What is shell terminal?
How to get script name inside a script?
What is shell chemistry?
How will you emulate wc –l using awk?
What is the significance of $#?
What is the difference between break and continue commands?
What language is bash written in?
What is the first line in a shell script?
What are the different types of shell scripting?