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.

Answers were Sorted based on User's Feedback



How to rename all the files in a folder having specific extension? Example: I have some files with..

Answer / ramit

Hi Nagesh,

Thanks for the reply but I dont think this will work
as $file= myFile.txt
and mv $file $file.my will rename to myFile.txt.my

I found the solution by extracting basedirectory and
filename then renaming it to req. extension.

thanks

Is This Answer Correct ?    2 Yes 4 No

How to rename all the files in a folder having specific extension? Example: I have some files with..

Answer / 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

How to rename all the files in a folder having specific extension? Example: I have some files with..

Answer / bindu

its very simple
try this out
rename .txt .my *.txt
all the files with .txt extension will be converted into .my

Is This Answer Correct ?    0 Yes 2 No

How to rename all the files in a folder having specific extension? Example: I have some files with..

Answer / nagesh

for file in *.txt
do
mv $file $file.my
done

Is This Answer Correct ?    5 Yes 10 No

How to rename all the files in a folder having specific extension? Example: I have some files with..

Answer / jks

It can be done using the xargs command of Unix ...
cd to the dir containing the *.txt files

$ls *.txt | xargs -i mv \{\} \{\}.my

Is This Answer Correct ?    5 Yes 15 No

Post New Answer

More Shell Script Interview Questions

What is bourne shell scripting?

0 Answers  


What is a shell in operating system?

0 Answers  


Devise a script that takes file name as arguement(which must present in the current directory)and locates from your home directory tree all thpath names of its links.Then mail the list to self.

0 Answers  


c program to check whether all the directories in the path exists has read and write permission

1 Answers  


what is the difference between sh & bash shell?

1 Answers  


What is the way to do multilevel if-else's in shell scripting?

0 Answers  


In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc.

9 Answers   Amazon,


How will you find the 99th line of a file using only tail and head command?

0 Answers  


What is option in shell script?

0 Answers  


What is the best shell scripting language?

0 Answers  


How do we create command aliases in a shell?

0 Answers  


How can we find the process name from its process id?

0 Answers  


Categories