Shell programming problem (Borne Shell or Korn Shell)How to change all files in a directory from one extension to another one? Thanks![香陵居士 (1-5 19:00, Long long ago)] [ 传统版 | sForum ][登录后回复]1楼
man renamerename .foo .bar *.foo[吴永铮 (1-5 20:29, Long long ago)] [ 传统版 | sForum ][登录后回复]2楼
(引用 吴永铮:man renamerename .foo .bar *.foo)Can not find such commandsngclrt01 mengdi 167: man rename
No manual entry for rename.
sngclrt01 mengdi 168: man -k rename
sngclrt01 mengdi 169: rename
ksh: rename: not found
sngclrt01 mengdi 170: sh
sngclrt01 mengdi 171: rename
sh: rename: not found[香陵居士 (1-6 10:36, Long long ago)]
[ 传统版 |
sForum ][登录后回复]3楼
mv *.abc *.xyz[逃课专家 (1-6 11:13, Long long ago)] [ 传统版 | sForum ][登录后回复]4楼
(引用 逃课专家:mv *.abc *.xyz)please do not guess...sngclrt01 mengdi 180: ls *.a
a.a b.a c.a
sngclrt01 mengdi 181: mv *.a *.b
mv: *.b not found[香陵居士 (1-6 12:08, Long long ago)]
[ 传统版 |
sForum ][登录后回复]5楼
(引用 香陵居士:please do not guess...sngclrt01 mengdi 180: ls *.a
a.a b.a c.a
sngclrt01 mengdi 181: mv *.a *.b
mv: *.b not found)for f in *.abcbase=(忘了).xyz
mv $f $base
done[逃课专家 (1-6 14:14, Long long ago)]
[ 传统版 |
sForum ][登录后回复]6楼
(引用 香陵居士:Can not find such commandsngclrt01 mengdi 167: man rename
No manual entry for rename.
sngclrt01 mengdi 168: man -k rename
sngclr...)可能是linux专有的吧# rpm -qf `which rename`
util-linux-2.12a-16
# man rename
RENAME(1) Linux Programmer's Manual RENAME(1)
NAME
rename - Rename files
SYNOPSIS
rename from to file...
DESCRIPTION
rename will rename the specified files by replacing the first occur-
rence of from in their name by to.
For example, given the files foo1, ..., foo9, foo10, ..., foo278, the
commands
rename foo foo0 foo?
rename foo foo0 foo??
will turn them into foo001, ..., foo009, foo010, ..., foo278.
And
rename .htm .html *.htm
will fix the extension of your html files.
SEE ALSO
mv(1)
1 January 2000 RENAME(1)
[吴永铮 (1-6 15:15, Long long ago)]
[ 传统版 |
sForum ][登录后回复]7楼
(引用 逃课专家:for f in *.abcbase=(忘了).xyz mv $f $base done)...[香陵居士 (1-6 18:18, Long long ago)] [ 传统版 | sForum ][登录后回复]8楼
not the most efficient one, since i am new to perl. but enough for your work#!/usr/bin/perl
@list = `ls test/*.b`;
foreach $a (@list){
chomp($a);
$com = "mv ".$a." $a.c";
exec($com);
}
assume your dir is "test" your old extension is .b , new one is .c
I hope to see perl experts to show me the greatest power of perl by doing same job using many and much more efficient ways :)
[MrDJay (1-6 20:41, Long long ago)]
[ 传统版 |
sForum ][登录后回复]9楼
看看这个可以么?没在公司,不能测试for example from *.abc to *.cde
source=`ls *.abc`
for file in $source
do
newfile=`echo $file | sed s'/.abc/.cde/g'`
#先不要用mv, 用echo看看$newfile名字对不,
#免得给你文件弄坏了
mv $file $newfile
done
[JiuJie (1-6 21:43, Long long ago)]
[ 传统版 |
sForum ][登录后回复]10楼
(引用 吴永铮:man renamerename .foo .bar *.foo)rename是函数吧,她要的应该是shell[JiuJie (1-6 21:47, Long long ago)] [ 传统版 | sForum ][登录后回复]11楼
(引用 吴永铮:可能是linux专有的吧# rpm -qf `which rename` util-linux-2.12a-16 # man rename RENAME(1) Linux Programmer's Manua...)应该是的[SmellsLikeTeenSpirit (1-7 1:07, Long long ago)] [ 传统版 | sForum ][登录后回复]12楼
(引用 MrDJay:not the most efficient one, since i am new to perl. but enough for your work#!/usr/bin/perl @list = `ls test/*.b`; foreach $a (@...)I mean shell script... :PPerl is not installed yet.[香陵居士 (1-7 9:33, Long long ago)] [ 传统版 | sForum ][登录后回复]13楼
(引用 香陵居士:I mean shell script... :PPerl is not installed yet.).........u...[MrDJay (1-7 10:15, Long long ago)] [ 传统版 | sForum ][登录后回复]14楼
(引用 JiuJie:看看这个可以么?没在公司,不能测试for example from *.abc to *.cde
source=`ls *.abc`
for file in $source
do
newfile=`echo $...)tested in Solaris 2.5 successfully.Before test:
~/tmp/test/[116]> ls
~/tmp/test/[116]> 1 2 1.abc 2.abc 3.dd
After test:
~/tmp/test/[116]> ls
~/tmp/test/[116]> 1 2 1.cde 2.cde 3.dd
Please try.[JiuJie (1-7 10:16, Long long ago)]
[ 传统版 |
sForum ][登录后回复]15楼
记得你好象曾经提起过有一个命令可以查当前是什么系统比如telnet进去,想知道是什么操作系统,什么机型.怎么实现呢? [JiuJie (1-7 10:18, Long long ago)] [ 传统版 | sForum ][登录后回复]16楼
(引用 JiuJie:记得你好象曾经提起过有一个命令可以查当前是什么系统比如telnet进去,想知道是什么操作系统,什么机型.怎么实现呢? )uname -a?[吴永铮 (1-7 12:12, Long long ago)] [ 传统版 | sForum ][登录后回复]17楼
(引用 JiuJie:rename是函数吧,她要的应该是shell)看清楚,是RENAME(1),不是RENAME(2)。[吴永铮 (1-7 12:13, Long long ago)] [ 传统版 | sForum ][登录后回复]18楼
(引用 吴永铮:uname -a?)谢谢[JiuJie (1-7 23:53, Long long ago)] [ 传统版 | sForum ][登录后回复]19楼