Rename small part of multiple files in middle of name using Bash?

前端 未结 4 1947
孤独总比滥情好
孤独总比滥情好 2021-02-04 04:15

I\'d just like to change this

cc211_AMBER_13062012i.II  cc211_GROMOS_13062012i.II
cc211_CHARM_13062012i.II  cc211_OPLS_13062012i.II

to

4条回答
  •  无人共我
    2021-02-04 04:48

    rename 's/_13/_15/' cc*
    

    Should do what you want. The regular expression s/_13/_15/ replaces _13 by _15 in all files starting 'cc'.

    $ ls
    cc211_AMBER_13062012.II  cc211_GROMOS_13062012.II
    cc211_CHARM_13062012.II  cc211_OPLS_13062012.II
    
    $ rename 's/_13/_15/' cc*
    
    $ ls
    cc211_AMBER_15062012.II  cc211_GROMOS_15062012.II
    cc211_CHARM_15062012.II  cc211_OPLS_15062012.II
    

    This will only work with the newer perl version of rename. To check which version you have do man rename. If the top of the page says

    Perl Programmers Reference Guide

    you have the perl version. If it says:

    Linux Programmer's Manual

    you have the standard (older) version.

    For the older version, the command should be:

    rename _13 _15 cc*
    

提交回复
热议问题