Bash Audio Files File Names

Rename Audio File Names to Music Titles in Bash

This article introduces how to rename audio file names to music titles using Bash.

Shou Arisaka
2 min read
Oct 5, 2025

You've ripped a CD, but the audio file metadata that should be readable from freedb or config files couldn't be retrieved, and you're stuck. So you had no choice but to rip them into wav or flac, but there's still no song name or anything written, and having them as "track 01" is confusing and very difficult to manage, right?

I wrote a script that can be used in such cases. Shell scripts like Bash have different quirks compared to other lightweight languages, and when trying to write something a bit complex, it takes quite a bit of time, which is a drawback...

Requirements: File names must be numbered in some form (containing track numbers, etc.) Necessary items: A file with new file names (titles) written line by line corresponding to track numbers <<e.g. names.txt>>

e.g.

$ ls
01 Track01.flac  03 Track03.flac  05 Track05.flac  07 Track07.flac  09 Track09.flac  11 Track11.flac
02 Track02.flac  04 Track04.flac  06 Track06.flac  08 Track08.flac  10 Track10.flac  12 Track12.flac
$ cat > names.txt
01 - Song Title 1
02 - Song Title 2
03 - Song Title 3
04 - Song Title 4
05 - Song Title 5
06 - Song Title 6
07 - Song Title 7
08 - Song Title 8
09 - Song Title 9
10 - Song Title 10
11 - Song Title 11
12 - Song Title 12

Run this for error handling: sed -i $'s/\t//' names.txt

Script

i=1
for f in *.flac ; do
name=$(sed "$(echo $i)q;d" names.txt)
mv "$f" "$name.flac"
i=$((i+1))
done

Replace .flac with .wav or any appropriate extension.

After execution

$ ls
01 - Song Title 1.flac  04 - Song Title 4.flac  07 - Song Title 7.flac  10 - Song Title 10.flac  names.txt
02 - Song Title 2.flac  05 - Song Title 5.flac  08 - Song Title 8.flac  11 - Song Title 11.flac
03 - Song Title 3.flac  06 - Song Title 6.flac  09 - Song Title 9.flac  12 - Song Title 12.flac

Share this article

Shou Arisaka Oct 5, 2025

๐Ÿ”— Copy Links