-1

I have a bunch of files starting with "NCI_" How can I rename them to start with "NCIB_" instead of "NCI_" I have tried using the below command in my folder containing the files:

rename 's/NCI_/NCIB_/' *

But it didn't work. Can anybody please help?

jww
  • 97,681
  • 90
  • 411
  • 885
Bindu
  • 21
  • 7
  • 1
    Possible duplicate of [Unix Renaming Files](https://stackoverflow.com/questions/45688086/unix-renaming-files) – gstukelj Sep 23 '19 at 11:11
  • 1
    Possible duplicate of [Rename multiple files based on pattern in Unix](https://stackoverflow.com/q/1086502/608639), [Rename all files in a folder with a prefix in a single unix command](https://stackoverflow.com/q/6329505/608639), [How to rename a certain prefix in multiple files?](https://askubuntu.com/q/878940), [Bulk rename, change prefix](https://unix.stackexchange.com/q/47367), etc. – jww Sep 23 '19 at 19:30

3 Answers3

1

You can use the rename command as shown below:

rename NCI_ NCIB_ *

Check the screenshot for sample output.

enter image description here

Harijith R
  • 329
  • 2
  • 8
0

Perhaps something like

find . -name "NCI_*" -exec bash -c 'mv $0 ${0/NCI_/NCIB_}' {} \;

Find files and perform rename using mv by replacing the old string with the new one.

Chris Gillatt
  • 1,026
  • 8
  • 13
-1

There are two tools called rename, one from util-linux and another one written in Perl. The Perl version is sometimes available in package managers as prename or perl-rename.

Check rename --help to find out which one you have. The util-linux rename prints something like this:

$ rename --help

Usage:
 rename [options] <expression> <replacement> <file>...
...

The Perl rename prints something like this (it's known as perl-rename on my Arch Linux system):

$ perl-rename --help
Usage: perl-rename [OPTION]... PERLEXPR FILE...
Rename FILE(s) using PERLEXPR on each filename.
...

With Perl rename, depending on the name of its executable on your system, your command should work:

$ perl-rename 's/NCI_/NCIB_/' *

But if you have the util-linux version, then it should be something like this:

$ rename NCI_ NCIB_ *
Thomas
  • 174,939
  • 50
  • 355
  • 478