0

I want to rename all the files in the current directory. So right now they are of the form: "xxx-9666_01.so", I want to rename it to "xxx_9444_01.so". How do I do it in Linux?

Arshad
  • 51
  • 6
  • You should explain the kind of change you want in the filenames, eg do you actually just want `9666` to become `9444` if encountered in a file name? I don't think that that's what you want. – fvu Jul 28 '16 at 20:52
  • Possible duplicate of [Renaming lots of files in Linux according to a pattern](http://stackoverflow.com/questions/6316600/renaming-lots-of-files-in-linux-according-to-a-pattern) – larsks Jul 28 '16 at 20:53
  • @fvu yes just that – Arshad Jul 28 '16 at 20:58
  • Try `rename '9666' '9444' ???_9666_01.so`. – alvits Jul 28 '16 at 21:39
  • The problem with `rename` is there are multiple `rename` executables with wildly different options. The standard `rename` installed by most distros from the `util-linux` package (from kernel.org), and the other (I believe perl `rename`). – David C. Rankin Jul 29 '16 at 00:58

2 Answers2

0

Using a loop:

for f in *-9666_01.so; do
  echo mv "$f" "${f%-9666_01.so}_9444_01.so"
done

Remove the echo when you're sure it's doing what you want it to do.

Kusalananda
  • 14,885
  • 3
  • 41
  • 52
0

A variation on the previous answer using parameter expansion with substring replacement (as opposed to substring removal) can accomplish the same goal, and may be a bit more readable:

for f in *-9666_01.so; do
    echo mv "$f" "${f/-9666/-9444}"
done

(remove echo when you are satisfied with the operation)

(where the substring replacement will replace a with b in f using the form ${f/a/b} (the closing / is implied) to replace the first instance of a with b, or ${f//a/b} to replace all instances of a with b)

David C. Rankin
  • 81,885
  • 6
  • 58
  • 85