F*V 发帖数: 3978 | 1 【 以下文字转载自 Linux 讨论区 】
发信人: FUV (扶危济贫), 信区: Linux
标 题: Re: 怎样用perl批量重命名文件 (转载)
发信站: BBS 未名空间站 (Thu Dec 8 19:40:28 2011, 美东)
j=1; for i in `ls out*` ; do mv $i prefix${i%.*}.$j ; ((++j)) ; done
try to run some tests before you actually do it. | t****t 发帖数: 6806 | 2 the order of this is probably not stable, since shell doesn't necessary sort
numerically, i.e. it can be out1, out11, out12, ..., out2, out21, ... etc.
then out11 -> out2 and you are in trouble.
【在 F*V 的大作中提到】 : 【 以下文字转载自 Linux 讨论区 】 : 发信人: FUV (扶危济贫), 信区: Linux : 标 题: Re: 怎样用perl批量重命名文件 (转载) : 发信站: BBS 未名空间站 (Thu Dec 8 19:40:28 2011, 美东) : j=1; for i in `ls out*` ; do mv $i prefix${i%.*}.$j ; ((++j)) ; done : try to run some tests before you actually do it.
| B*V 发帖数: 3365 | 3 you are right about the order issue and that's why I used
"mv $i prefix${i%.*}.$j"
not
"mv $i ${i%.*}.$j" to avoid that.
sort
.
【在 t****t 的大作中提到】 : the order of this is probably not stable, since shell doesn't necessary sort : numerically, i.e. it can be out1, out11, out12, ..., out2, out21, ... etc. : then out11 -> out2 and you are in trouble.
|
|