Linux cp with a regexp

后端 未结 3 886
孤街浪徒
孤街浪徒 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 13:00

    I really like the regex syntax of the rename perl script (by Robin Barker and Larry Wall), e.g.:

    rename "s/OldFile/NewFile/" OldFile*

    OldFile.c and OldFile.h are renamed to NewFile.c and NewFile.h, respectively

    I simply wanted the exact same thing with a copy command:

    copy "s/OldFile/NewFile/" OldFile*

    So I duplicated that script and changed the rename statement to copy via File::Copy. Et voila! A copy command with perl-regex syntax:

    https://gist.github.com/jcward/0ead33bd79f2061c68728cc82582241f

提交回复
热议问题