Operating System - Linux
1828342 Members
3181 Online
109976 Solutions
New Discussion

Re: error with script to change file name in directory

 
SOLVED
Go to solution
Ratzie
Super Advisor

error with script to change file name in directory

I can get each part to work but when I put it all together I get an error.
ls -l|while read file
do newname=`echo $file|sed -e "s/02-Aug/0208/g"`
mv "$file" "$newname"
done

Error I get:
Try `mv --help' for more information.
4 REPLIES 4
Gopi Sekar
Honored Contributor
Solution

Re: error with script to change file name in directory


your problem is 'ls -l|while read file'

as you know ls -l will do long list of the file (including permission, user name, group name owned, size etc). mv does not recognize all these and require only file name.

so, to solve use 'ls -1|while read file'

the option to use is number one.

Hope this helps,
Gopi
Never Never Never Giveup
morganelan
Trusted Contributor

Re: error with script to change file name in directory

Hi,
Change your mv script line such as:

mv $file $newname
Kamal Mirdad
Raj D.
Honored Contributor

Re: error with script to change file name in directory

Hi LHradowy ,

Try with ls or ls -1 [ ls -l will give long listing and give error]
and then u can rename all with adding 0208 .

Hope this will make it simple.
Cheers ,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Ratzie
Super Advisor

Re: error with script to change file name in directory

Did not know ls -1 works!