用bash批量重命名

某人让我把某系统插件的主文件名由repository.class.php改成lib.php(真闲的蛋痛),一个个改也行,但之后还可能让我干把icon.png改成pix/icon.png之类的事,所以弄个脚本吧:

for i in ./*/repository.class.php;
do
    newpath=`echo $i|sed 's/repository.class.php/lib.php/g'`;
    mv $i $newpath;
done

单行:

for i in ./*/repository.class.php; do newpath=`echo $i|sed 's/repository.class.php/lib.php/g'`; mv $i $newpath; done

不知道还有没有更好的办法?欢迎指教。

Reference: RENAME MULTIPLE FILES IN BASH USING REGULAR EXPRESSIONS

This entry was posted in OS and tagged .

One comment to 用bash批量重命名

  1. Redsky says:

    兄弟能否联系下?我们正在使用Moodle平台进行二次开发呢,,,希望能收到你的邮件。祝你顺利!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>