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

for file in `ls` ; do NEW=`echo $file | sed 's/.txt/.my/g'`
; mv $file $NEW ; done

Is This Answer Correct ?    10 Yes 0 No

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

Answer / akshay telang

for i in `find . -name "*.txt"`
> do
> mv $i ${i%.txt}.my
> done

Is This Answer Correct ?    11 Yes 4 No

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

Answer / asit pal

foreach x (`ls *.txt')
set y = `echo $x | cut -d . -f 1`
mv y y.my
done

Is This Answer Correct ?    1 Yes 0 No

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

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

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

Answer / geichel

#!/bin/bash

for x in $(find $1 -name '*.txt' -type f )
do
OUT=$(echo $x | sed -e "s/\.txt$/.my/")
mv $x $OUT
done


exit 0;

Is This Answer Correct ?    0 Yes 0 No

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

Answer / venugopal adep

for file in `ls *.txt`; do new_file=`echo $file | sed
's/txt/my/g'`; mv $file $new_file; done

Is This Answer Correct ?    0 Yes 0 No

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

Answer / indu sharma

find . -name "*.txt" -exec ls {} \; | xargs -n1 -I{} sh -c 'mv "{}" `echo "{}"|basename "{}" .txt`.my'

Is This Answer Correct ?    1 Yes 1 No

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

Answer / sushanta

for i in *
do
p=`basename $i c`
q=$p "txt"
mv $i $q
done

Is This Answer Correct ?    0 Yes 0 No

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

Answer / veera

rename replacing-text replaced-test list-of-files
ex: rename .txt .my *.txt

Is This Answer Correct ?    0 Yes 0 No

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

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

More Shell Script Interview Questions

How to open a read-only file in the shell?

0 Answers  


What shell is bin sh?

0 Answers  


How do we delete all blank lines in a file?

0 Answers  


Why should we use shell scripts?

0 Answers  


What are the different variables present in linux shell?

0 Answers  


What is meant by dos operating system?

0 Answers  


How are shells born?

0 Answers  


how do you write sql queries using shell script for eg:- we have databae table like EMPNO,ENAME,SAL,DEPTNO columns in EMP table how you display EMPNO,SAL FIELDS from emp in SHELL SCRIPT please explain with an example

4 Answers  


How to modify the PATH variable and make it executable?

3 Answers   Mind Tree,


what is the difference between cmp and diff commands

2 Answers   Amazon, CTS,


write a shell script that counts a number of unique word contained in the file and print them in alphabetical order line by line?

6 Answers   IBM, Wipro,


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

0 Answers  


Categories