1

This question already has an answer here:

I have following image files in some directory which I want to be renamed:

8 -rw-rw-r-- 1 6661 sep 24 10:28 dbConnectionOkBostjan.png
8 -rw-rw-r-- 1 6548 sep 24 10:29 dbConnectionErrorBostjan.png
8 -rw-rw-r-- 1 5708 sep 24 10:29 btConnectionErrorBostjan.png
8 -rw-rw-r-- 1 5911 sep 24 10:30 btConnectionOkBostjan.png
8 -rw-rw-r-- 1 6916 sep 24 10:31 userLogOkBostjan.png
8 -rw-rw-r-- 1 6924 sep 24 10:44 userLogErrorBostjan.png

Now, I know how to use mv command to rename file and I even know how to rename multiple files, but in this case I want to rename every this file with new name same as original file, but without word Bostjan. For example, dbConnectionOkBostjan.png must rename to dbConnectionOk.png and same for all other files. How do achieve this task using terminal? I wish to solve this using ordinary mv command. If I use proposed solution from Answer 1, I get following errors:

user@testcomp:~/Pictures/testAppIcons$ for i in *Bostjan*; do mv $i $(echo $i | sed @Bostjan@@); done sed: -e expression #1, char 1: unknown command: `@' mv: missing destination file operand after ‘btConnectionErrorBostjan.png’ Try 'mv --help' for more information. sed: -e expression #1, char 1: unknown command: `@' mv: missing destination file operand after ‘btConnectionOkBostjan.png’ Try 'mv
--help' for more information. sed: -e expression #1, char 1: unknown command: `@' mv: missing destination file operand after ‘dbConnectionErrorBostjan.png’ Try 'mv --help' for more information. sed: -e expression #1, char 1: unknown command: `@' mv: missing destination file operand after ‘dbConnectionOkBostjan.png’ Try 'mv
--help' for more information. sed: -e expression #1, char 1: unknown command: `@' mv: missing destination file operand after ‘userLogErrorBostjan.png’ Try 'mv --help' for more information. sed:
-e expression #1, char 1: unknown command: `@' mv: missing destination file operand after ‘userLogOkBostjan.png’ Try 'mv --help' for more information. user@testcomp:~/Pictures/testAppIcons$

I am using KUbuntu 15.04.

marked as duplicate by Archemar, John WH Smith, X Tian, Anthon, muru Sep 24 '15 at 10:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @Archemar I think this is not a duplicate since I want to solve this using mv, not perl's rename. – KernelPanic Sep 24 '15 at 11:00
2

That can be done in one line, though for legibility I'll split. I echo the filename and modify it using sed in the target argument of mv:

for i in *Bostjan*; do
  mv $i $(echo $i | sed s@Bostjan@@)
done
0

Use mmv. (You may have to install it first.) mmv "*Botsjan*" "#1#2"

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