I have a bash script that uses the rename command as follows:
sudo rename 's/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/Date-$1-$2-$3__Time-$4:$5:$6/' 2019*
According to the rename man page the command should overwrite by default and not overwrite by using the -o flag. But when I run the script it is not overwriting existing files. However I get an error thrown back and the duplicate files do not get any other processing done by the script.
Renaming Files
20190710220231.WAV not renamed: Date-2019-07-10__Time-22:02:31.WAV already exists 20190710220300.WAV not renamed: Date-2019-07-10__Time-22:03:00.WAV already exists 20190710220338.WAV not renamed: Date-2019-07-10__Time-22:03:38.WAV already exists 20190710220349.WAV not renamed: Date-2019-07-10__Time-22:03:49.WAV already exists
Frustrated, I tried to just use the mv command but gives me a different error:
mv: target '20190710222433.WAV' is not a directory
So I added a / and get the same error. Any advice?
you can use the option -f
to force over write existing files:
rename -f ...
man rename:
-f, --force
Over write: allow existing files to be over-written.