Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: renaming with number prefix
- X-seq: zsh-users 1257
- From: Thomas Koehler <thomas@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxxxxxxx
- Subject: Re: renaming with number prefix
- Date: Fri, 23 Jan 1998 17:21:16 +0100
- In-reply-to: <19980123165404.53612@xxxxxxxxxxxxxxxxx>; from Sven Guckes on Fri, Jan 23, 1998 at 04:54:04PM +0100
- References: <19980123165404.53612@xxxxxxxxxxxxxxxxx>
On Fri, Jan 23, 1998 at 04:54:04PM +0100, Sven Guckes wrote:
> Problem:
> Rename all files within a directory such that their names
> get a numeral prefix in the default sort order.
>
> Example:
>
> $ ls
> abc bar baz foo zyxxy
> $ <command>
> $ ls
> 1.abc 2.bar 3.baz 4.foo 5.zyxxy
>
> So - what's that <command>?
w=1 ; for i in `ls` ; do mv $i ${w}.${i} ; w=$[w+1] ; done
Not very elegant, perhaps...
> Btw, "leading zeroes" would be a bonus.
w=1 ; for i in `ls` ; do
if [ $w -gt 99 ] ; then
mv $i ${w}.${i} ; w=$[w+1]
else if [ $w -gt 9 ] ; then
mv $i 0${w}.${i} ; w=$[w+1]
else
mv $i ${w}.${i} ; w=$[w+1]
fi
fi
done
> Sven
CU,
Thomas
Messages sorted by:
Reverse Date,
Date,
Thread,
Author