Multi rename in Linux bash

I trying to rename my file(date yesterday)1, file(date yesterday)2,3,4,5... using this code.

echo dir date?
read datedir
cd /mnt/c/Users/OPS\ 1/Desktop/F/CVS/CVS\ COMPONENTS/CVS$datedir
echo date now?
read datetd
echo last date?
read lastdate
rename -v 's/$lastdate/$datetd/g' *$lastdate

1 answer

  • answered 2018-11-08 12:00 kvantour

    After reading man rename I see what you are trying to do:

    Your rename command is used wrong. Update it with the following:

    rename "$lastdate" "$datetd" *$lastdate

    SYNOPSIS: rename from to file...

    DESCRIPTION: rename will rename the specified files by replacing the first occurrence of from in their name by to.

    source: man rename