Recently I found myself in possession of some music where the entire album was a single FLAC file. Each FLAC file came along with a cue file (also known as a cue sheet), which simply defines when, in seconds from the start, each individual track begins. This is fine for archival purposes, when you just want a backup of an existing CD, but it makes it awkward if you just want to listen to a single song off an album. Luckily, the Ubuntu repositories contain some tools that make splitting the file into individual tracks incredibly simple.
The program we will use to split the tracks is called
shntool, and we’ll also need
flac, if you don’t have those installed already:
sudo apt install shntool cuetools flac
Note, if you’re using an older version of Ubuntu (pre-16.04) you’ll need to replace
apt-get. Once you have these installed, navigate to the folder than contains your FLAC and cue files. You can then split the files using the following command, replacing
flacfile.flac with the names of your respective files:
shnsplit -f cuefile.cue -t "%n %t" -o "flac flac -8 -o %f -" flacfile.flac
As long as your cue file contains track name data, this should output the files
01 Name of Track 1.flac 02 Name of Track 2.flac etc. The created files won’t have any tag data though, so we’ll use one of the scripts included with
cuetools to add it:
cuetag cuefile.cue [0-9]*.flac
You can delete the whole album FLAC file once you’ve finished splitting it,
shntool can be used to recombine the split files into a single file should you ever need it, using
shnjoin *.flac -o flac. You can also delete the cue file, although should you ever want to burn a CD from your FLAC files you might want to keep it, because I’m not 100% sure if burning the individual files would produce the same results as using the combined file plus a cue file (because of things like pre-gaps). They are usually only a few kilobytes so don’t take up much space.