Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Which shell is the best?

980


How do scripts work?

1030


What does echo $0 do?

951


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.

1021


What is ms powershell?

1000


Explore about environment variables?

1026


What are the two files of crontab command?

1212


How do I open the shell prompt?

1179


How to check if the previous command was run successfully?

1019


What is the difference between bash and shell?

1104


Which scripting language is best for automation?

948


How does ls command work?

1014


What is bash coding?

914


madhar chod unix ke 10 commands dhang se likh nahi sakta hai

3465


How can you find out how long the system has been running?

892