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 / prav gir

#!/bin/sh
for filename in *$1*
do
echo "$filename"
mv -f "$filename" `echo $filename|sed "s/$1/$2/"`
done
run script like
$>scrpt1 .txt .my

Is This Answer Correct ?    3 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to set an array in linux?

598


What are the advantages of shell script?

524


How do I run a shell script on a mac?

631


Explain about echo command?

625


is this growing field and what is average package in this?

1872






How will you emulate wc –l using awk?

913


Calculate a real number calculation directly from the terminal and not any shell script.

659


What is the syntax of "nested if statement" in shell scripting?

631


Why is the use of shell script?

543


Explain about gui scripting?

626


What is the best scripting language?

566


Is cmd a shell?

598


How will you connect to a database server from linux?

557


Write a command sequence to find all the files modified in less than 2 days and print the record count of each.

936


How to get the 3rd element/column from each line from a file?

694