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 / aravind s

basename is the appropriate command to cut the unwanted
string from a filename

for example
$basename unix.txt txt #txt stripped off
unix.
-----------------------
for your problem the solution is

for i in `find . -name '*.txt'`|xargs ls; do
leftname=`basename $i txt`
mv $i ${leftname}doc
done
-----------------------

basename isn't a shell bulletin, but an external command.
The reason why we deal with it here is that it's most
effective when used with the for loop.

Ref: Unix Concepts & Applications - Sumitabha Das

Is This Answer Correct ?    2 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why are shell scripts used?

1116


What are scripts in psychology?

1117


What is sh in shell script?

1064


How do you find out What is your shell?

1098


What shell is bin sh?

1016


What is path variable bash?

1087


Write a shell script to get current date, time, user name and current working directory.

1132


one folder contains lot of students name but I want to fetch hello with every student name individually using shell script

996


What is bash command used for?

1114


How do I debug a shell script?

1122


How do you know which shell I am using?

1087


What are the various stages of a linux process it passes through?

1248


What will happen to my current process when I execute a command using exec?

1126


How do I edit a .sh file?

1205


What are the 3 standard streams in linux?

1203