Question: I have a file directory `music/artist/{random_name}/{random_music}.ogg`

There's a lot of folder in `{random_name}` and different kind of music title `{random_music}`.

So, I wanted to rename the `{random_music}.ogg` to `music.ogg`. Each `{random_name}` folder only have one .ogg files. 

I've tried with the Bash scripts for hours but didn't managed to find out.

```
for f in ../music/artist/*/*.ogg
do
  echo mv  "$f" "${f/.*.ogg/music.ogg}"
done

```

It only rename the file on my current dir, which will ask for replace/overwrite.

My goals is, I wanted to rename all the `{random_music}.ogg` files to `music.ogg` with their respective directories for example, 

`music/artist/arai/blue.ogg` to `music/artist/arai/music.ogg`

`music/artist/sako/sky.ogg` to `music/artist/sako/music.ogg`

Answer: 
Your pattern replacement is incorrect. Because all your paths start with `..`, `.*.ogg` actually matches *the entire path*, so *every* file gets turned into `music.ogg` in your current directory.

You want `${f/\/*.ogg/music.ogg}` instead, or better yet, `${f%/*}/music.ogg`. That's the rough equivalent of `"$(dirname "$f")"/music.ogg`.
I hope this would help you:

Previously:

```
[root@user]# tree music
music
└── artist
    ├── df
    │   └── mp.ogg
    ├── gh
    │   └── pl.ogg
    ├── jk
    │   └── gl.ogg
    ├── po
    │   └── ui.ogg
    ├── ty
    │   └── lk.ogg
    └── ui
        └── dh.ogg

7 directories, 6 files

```

Source code:

```
#!/bin/bash

for i in `ls -ld music/artist/* | awk '{print $9}'`
do
        mv $i/*ogg $i/music.ogg

done

```

After execution:

```
music
└── artist
    ├── df
    │   └── music.ogg
    ├── gh
    │   └── music.ogg
    ├── jk
    │   └── music.ogg
    ├── po
    │   └── music.ogg
    ├── ty
    │   └── music.ogg
    └── ui
        └── music.ogg

7 directories, 6 files

```

As you can see all of the files got renamed correctly.