'SSH command to replace/convert spaces from images file with underscores in a directory

I want to remove spaces from .jpg files and convert/replace spaces in underscores.

Current files name : image 1 2.jpg
I want it to be become: image_1_2.jpg

These are all images files inside a directory /home/website/www/import and there are many files with different names but I want only .jpg extension file to change space with underscore.

This command not worked:

find -name "* *.jpg" -type f | rename 's/ /_/g'

I run it from root and shows this :

rename: not enough arguments

Kindly provide me correct command

centos 7.5
root access



Solution 1:[1]

You can use find -exec for something like that:

find ./ -name "* *.jpg" -exec rename  's/ /_/g' {} \;

(not tested, but it should be something like that)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dominique