2

I have three files in a directory (in mac-osx terminal) say

INIT_Struc1
INIT_Struc2
INIT_Struc3

which I need to rename as

FINAL_Struc1
FINAL_Struc2
FINAL_Struc3

When I use the rename command (installed through homebrew) as

rename -n 's/\INIT_$/FINAL_/' INIT_*

it does not rename the files. What am I doing wrong with the rename command that fails to rename the files.

  • 2
    Drop the $, it means end of string, but the string doesn't end, yet. – Marco Oct 6 '15 at 13:21
  • Leave the -n flag: no action. – chaos Oct 6 '15 at 13:21
5
  1. this rename will replace INIT_ as final part of filename. (foo.INIT_ would be renamed to foo.FINAL_, on REGEXP paradign '$' is end of line '^' beginning etc ... )
  2. \I lead to an unknow switch for rename

try

 rename -n s/INIT_/FINAL_/ $(find . -print )

for a preview.
where

  • -n flag is for preview
  • $(find . -print ) will go down directory (from local dir), LHS(*) of rename will filter name.

    rename s/INIT_/FINAL_/ $(find . -print )

no need for quotes, if no funny name.

(*) stand for Left Hand Side.

  • right without the -n – lese Oct 6 '15 at 13:23
  • That worked, is it because $ sign indicates the end of string (or filename) ? – WanderingMind Oct 6 '15 at 13:23
  • This fails if I try to rename sub-directories. Can you please update the answer as to how I can rename sub-directories as well. – WanderingMind Oct 6 '15 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.