I have organised the compilations in my music library with the following structure:/music/<artist>_<album>/cd1/music/<artist>_<album>/cd2

Every file in the directory has this naming convention:<nn>_<title>.mp3(e.g. 01_hereisthetitle.mp3)

The script should search for the compilations and identify them automatically.Then, every file in directory cd1 should be renamed to 1-<nn>_<title>.mp3 (e.g. 1-01_hereisthetitle.mp3), and every file in directory cd2 should be renamed to 2-<nn>_<title>.mp3 (e.g. 2-01_hereisanothertitle.mp3).

Can you provide some input for the syntax of a bash script performing this task?

This renames any mp3 file that is located in a directory called cd1 to cd9, and renames it as you shared. It leaves the mp3 file in the same directory. Did you mean you also wanted to move the files one directory up, so you don't need the cd1 to cd9 directories any more? Then run it as this command instead: