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

How to pass an argument to a script?

1204


What is @echo off?

1009


What is a command line shell?

1045


What exactly is a shell?

1080


Explain about return code?

1071


How can the contents of a file inside jar be read without extracting in a shell script?

1127


How do you create a shortcut in linux?

1200


I have 2 files and I want to print the records which are common to both.

1163


What is the command to find out users on the system?

970


How do you debug a script?

1068


what is tickets $ what low,medium,high priorite pls define time also

2154


shell script for reverse the string

1400


How to check if a directory exists?

1192


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

3471


Suppose you execute a command using exec, what will be the status of your current process in the shell?

1070