1831912 Members
3771 Online
110031 Solutions
New Discussion

rename files

 
SOLVED
Go to solution
Michael_33
Regular Advisor

rename files

Hi All,

I want to rename all *.png
files to *.gif under /opt.
How can I do?

Thanks!
9 REPLIES 9
Michael Tully
Honored Contributor

Re: rename files

Hi,

echo *.png |while read i
do
mv $i ${i%png}gif
done

HTH
-Michael
Anyone for a Mutiny ?
S.K. Chan
Honored Contributor

Re: rename files

Try this ..
# cd /opt
# for file in `ls *.png|awk -F"." '{print $1}'`
>do
>mv $i.png $i.gif
>done

Not so elegant but it works.
Michael_33
Regular Advisor

Re: rename files

thanks all!

but when I run, I got this:

"arg list too long"

maybe need to change some kernel parameter?

Michael Tully
Honored Contributor
Solution

Re: rename files

One more just for the hell of it:

for i in $(ls *.png)
do
mv $i $(basname $i .png).gif
done
Anyone for a Mutiny ?
S.K. Chan
Honored Contributor

Re: rename files

Yes , you need to change a kernel parameter for this .. ie 'large_ncargs_enabled'.The default is 20478 bytes, but you can increase this value to 2048000 by setting
large_ncargs_enabled = 1' (default is 0).

Run this to check .

# getconf ARG_MAX

what you currently got.
S.K. Chan
Honored Contributor

Re: rename files

Forgot one more thing, if you are running 11.0 and above the value is already set to 2048000 by default. You've got to be running 10.20, right ?
Michael Tully
Honored Contributor

Re: rename files

Without changing kernel parameters you could try this.... I haven't got anything to test it on:

find /opt -type f -name "*.png" | xargs -i mv {}.png {}.gif
Anyone for a Mutiny ?
SHABU KHAN
Trusted Contributor

Re: rename files

Hi,

Here is another method:

cd /opt
for i in *.png
do
echo ${i}
mv ${i} `basename ${i}.gif`
done

Thanks,
Shabu
SHABU KHAN
Trusted Contributor

Re: rename files


Michael's xargs command should fix your "arg list too long" problem ...

xargs has more buffer ..

-Shabu