Linux cp with a regexp

后端 未结 3 887
孤街浪徒
孤街浪徒 2021-02-10 12:11

I would like to copy some files in a directory, renaming the files but conserving extension. Is this possible with a simple cp, using regex ?

For example :

3条回答
  •  太阳男子
    2021-02-10 12:47

    Suppose you have myfile.a, myfile.b, myfile.c:

    for i in myfile.*; do echo mv "$i" "${i/myfile./newname.}"; done
    

    This creates (upon removal of echo) newname.a, newname.b, newname.c.

提交回复
热议问题