1

I wanted to change all of the files extensions in a folder to .jpg using only sed command.

I tried using

sed -i 's/\.*/\.jpg/g' ~/cw/ 

cw is my folder where i have files like:

  • cat.jpg

  • dog.JPG

  • frog.jpeg

etc.

HatLess
  • 10,622
  • 5
  • 14
  • 32
wyntia
  • 25
  • 5
  • Does this answer your question? [Using sed to mass rename files](https://stackoverflow.com/questions/2372719/using-sed-to-mass-rename-files) – Maroun Apr 06 '22 at 14:20
  • not really, I wanted to change .jpeg, .JPG and not the names of the files – wyntia Apr 06 '22 at 14:32

1 Answers1

1

Using sed

sed -n 's/\(^[^.]*\.\)[jJ][pP]e\?[gG]/mv & \1jpg/p' <(find ~/cw/)

If the dry run indeed changes the files to the expected extension, then you can then execute the command within the sed command

sed -n 's/\(^[^.]*\.\)[jJ][pP]e\?[gG]/mv & \1jpg/pe' <(find ~/cw/)
HatLess
  • 10,622
  • 5
  • 14
  • 32