How to rename multiple files in a directory? Suppose I have 20 .txt files in a directory.Now I want to rename these files to .doc I tried mv *.txt *.doc but I got message that while moving multiple files last argument must be a directory. Please tell me how to do it.
How to rename multiple files in a directory? Suppose I have 20 .txt files in a directory.Now I want to rename these files to .doc I tried mv *.txt *.doc but I got message that while moving multiple files last argument must be a directory.
Try the following :
for i in *.txt; do j=`expr "$i" : "(.*).txt"`.doc; mv $i $j; done
- Keyur
On Thu, 26 Jul 2001, Keyur Shroff wrote:
I tried mv *.txt *.doc but I got message that while moving multiple files last argument must be a directory.
Try the following :
for i in *.txt; do j=`expr "$i" : "(.*).txt"`.doc; mv $i $j; done
If you use bash, this will be easier:
for i in *.txt; do mv $i ${i%.txt}.doc; done
The ${i%.txt} construct returns the value of $i with any trailing .txt stripped from it.
Philip
--- Nikhil Joshi nikhiljoshy@yahoo.com wrote:
How to rename multiple files in a directory?
The best way it to write a pipe to do this. The commands to use are ls, xargs which will feed the name of one file at a time to mv. Figure out how to work with shell variables and you are through.
I am no good at shell programming, but this is the right direction, AFAIK.
SameerDS.
__________________________________________________ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/