How to batch rename files and use the file its own name content with Bash
In my example the files had the right content in their name only the position was wrong.
The original files their name were:
The file title - vendor_1.mp3
The file title - vendor_4.mp3
The file title - vendor_22.mp3
The file title - vendor_39.mp3
But afterwards I found this is a difficult way of searching on a vendor. Which I do the most.
So, I decided to make a simple rename script to move the vendor to the beginning of the file name and the title to the end of the filename.
This would give the following filenames as result:
vendor_1 - The file title.mp3
vendor_4 - The file title.mp3
vendor_22 - The file title.mp3
vendor_39 - The file title.mp3
I hope you find this useful or that you can modify it for your own use. You can see the tiny script I used below.
#!/usr/local/bin/bash root="/my/files/location" find $root -type f | while read file do filename=${file##*/} piece1=${filename%% - *} piece2=${filename##* - } extension=${filename##*.} newfile="${piece2%%.$extension} - ${piece1}.$extension" mv "${file}" "${root}/${newfile}" done




