I don't know about perl syntax and perl scripting but I can help you to rename all .jpg files with its rename
command as following:
First you have to switch the directory that you have all .jpg there. for example if files are stored in /home/star1017/jpg-file
, I type like this:
cd /home/star1017/jpg-file
then run
rename -n 's/(.*)\.jpg$/prefix_$1.jpg/' *.jpg
Match everything (.*)
which is ends$
with .jpg
then add a prefix_
and print matched group$1
(this means print the matched group by using its back-reference) and then print the extension. Command runs for all *.jpg
files.
Test:
file01.jpg renamed as prefix_file01.jpg
file02.jpg renamed as prefix_file02.jpg
file03.jpg renamed as prefix_file03.jpg
file04.jpg renamed as prefix_file04.jpg
file05.jpg renamed as prefix_file05.jpg
Or if you don't want to switch to that directory, run this:
rename -n 's/(.*)\/(.*)\.jpg$/$1\/prefix_$2.jpg/' /home/star1017/jpg-file/*.jpg
at the end, if you ensure the test, remove -n
option to real rename on actual files.