Using regex with `rename` version from `util-linux`

后端 未结 2 760
温柔的废话
温柔的废话 2021-01-05 00:25

I’m using a GNU/Linux distribution where the utility rename comes from util-linux and I want to make full use of regular (Perl or POSIX) expression

相关标签:
2条回答
  • 2021-01-05 01:16

    Here is the manual page: http://linux.die.net/man/1/rename. It is pretty straightforward:

    rename from to file...

    rename will rename the specified files by replacing the first occurrence of from in their name by to.

    I believe there are no regexes, it is just plain substring match.

    0 讨论(0)
  • 2021-01-05 01:24

    The following command gives the expected result with your input file but using the perl version:

    rename 's/foo_\D+(\d+)/foo_$1/' *.ext
    

    You can test the command using -n option to rename

    0 讨论(0)
提交回复
热议问题