2

I am trying to rename a word in the file name of multiple JPEG files from Hoddesden to Hoddesdan.

How can I do it on the Ubuntu command line?

Examples

R59-GBR_Hoddesden_2015-08-21_15-48-00-190_UNKNOWN.jpg
to 
YR59-GBR_Hoddesdan_2015-08-21_15-48-00-190_UNKNOWN.jpg 

YR59FRP-GBR_Hoddesden_2015-08-21_15-47-59-222_APPROACH
to
YR59FRP-GBR_Hoddesdan_2015-08-21_15-47-59-222_APPROACH

marked as duplicate by Jacob Vlijm, A.B., Rmano, Eric Carvalho, karel Sep 2 '15 at 6:38

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.

  • Do you mean YR59FRP-GBR_Hoddesden_2015-08-21_15-47-59-222_APPROACH.jpg instead of YR59FRP-GBR_Hoddesden_2015-08-21_15-47-59-222_APPROACH? – A.B. Sep 1 '15 at 11:33
  • 3
    Also: askubuntu.com/questions/58546/… and quite a few others :) – Jacob Vlijm Sep 1 '15 at 11:37
  • @JacobVlijm I would say, a ton =) – A.B. Sep 1 '15 at 11:40
11

With rename

rename 's/Hoddesden/Hoddesdan/' *.jpg

Example

% ls -laog *.jpg
-rw-rw-r-- 1 0 Sep  1 13:30 R59-GBR_Hoddesden_2015-08-21_15-48-00-190_UNKNOWN.jpg
-rw-rw-r-- 1 0 Sep  1 13:30 YR59FRP-GBR_Hoddesden_2015-08-21_15-47-59-222_APPROACH.jpg

% rename 's/Hoddesden/Hoddesdan/' *.jpg

% ls -laog *.jpg
-rw-rw-r-- 1 0 Sep  1 13:30 R59-GBR_Hoddesdan_2015-08-21_15-48-00-190_UNKNOWN.jpg
-rw-rw-r-- 1 0 Sep  1 13:30 YR59FRP-GBR_Hoddesdan_2015-08-21_15-47-59-222_APPROACH.jpg
  • 2
    Nice to hear that, but don't thank me, simply accept my answer with a click on the icon at the left hand side of my answer =) – A.B. Sep 1 '15 at 11:39
6

You can use rename (prename) :

rename -n 's/Hoddesden/Hoddesdan/' *Hoddesden*

-n is for dry run, if you are satisfied with the changes remove -n to let the operation take place :

rename 's/Hoddesden/Hoddesdan/' *Hoddesden*
  • What should I say? Simply: ;) – A.B. Sep 1 '15 at 11:36
5

We also have rename.ul (rename is a perl command).

rename.ul Hoddesden Hoddesdan *Hoddesden*

$ ls 
R59-GBR_Hoddesden_2015-08-21_15-48-00-190_UNKNOWN.jpg
YR59FRP-GBR_Hoddesden_2015-08-21_15-47-59-222_APPROACH
$ rename.ul Hoddesden Hoddesdan *Hoddesden*
$ ls 
59-GBR_Hoddesdan_2015-08-21_15-48-00-190_UNKNOWN.jpg
YR59FRP-GBR_Hoddesdan_2015-08-21_15-47-59-222_APPROACH
1

With mmv, install by

sudo apt-get install mmv

and use as following:

mmv '*Hoddesden*.jpg' '#1Hoddesdan#2.jpg'
  • You need to install mmv 1st. – Rinzwind Sep 1 '15 at 15:34

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