A bash script that automatically splits single FLAC music album files into individual song tracks using CUE sheet information.
When digitizing an LP or ripping a CD to lossless format, the result is usually a single large FLAC file containing the entire music album, accompanied by a CUE sheet that defines individual song track boundaries. Popular ripping software like EAC (Exact Audio Copy), dBpoweramp, Whipper, and Rip Station often create these FLAC+CUE pairs to preserve perfect audio quality. While this format preserves the original recording perfectly, it's not convenient for modern music players that expect individual song files.
This script bridges that gap by:
- Splitting large music album files into individual song tracks
- Preserving audio quality (lossless FLAC-to-FLAC conversion)
- Organizing files with consistent naming (
01 - Song Title.flac) - Sanitizing filenames for cross-platform compatibility
- šµ Lossless splitting using shntool
- š Recursive processing - automatically finds and processes all FLAC+CUE pairs in an entire directory tree
- š Smart duplicate detection (won't re-split already processed albums)
- š„ļø NTFS compatibility (sanitizes problematic characters in track names)
- š”ļø Safe operation (renames originals to
.delinstead of deleting) - š Clear progress feedback with status messages
The script automatically sanitizes CUE file song titles to ensure compatibility with Windows NTFS filesystems by replacing problematic characters:
| Character | Replacement | Reason |
|---|---|---|
? * < > | / \ : |
- |
Reserved/illegal in Windows filenames |
Curly quotes (' ') |
- |
Encoding issues across systems |
This ensures your music library works seamlessly whether you're on Linux, macOS, or Windows.
The script requires these tools to be installed:
- shntool - for splitting audio files
- flac - for FLAC codec support
- Standard Unix tools (
sed,find,basename, etc.)
sudo apt-get install shntool flac
brew install shntool flac
sudo dnf install shntool flac
After installing the prerequisites above, you need to make the script available on your system:
sudo cp split_flac.sh /usr/local/bin/split_flac sudo chmod +x /usr/local/bin/split_flac
mkdir -p ~/.local/bin cp split_flac.sh ~/.local/bin/split_flac chmod +x ~/.local/bin/split_flac
Make sure ~/.local/bin is in your PATH (it usually is by default on modern Linux distributions).
The power of this script lies in its recursive processing capability. Simply navigate to the top-level directory containing your music collection and run:
split_flac
The script will automatically:
- Traverse the entire directory tree recursively
- Find all music album FLAC+CUE file pairs at any depth
- Process each album it discovers
- Skip directories that have already been processed
This means you can organize your music collection like this:
Music/
āāā Artist 1/
ā āāā Album A/
ā ā āāā Album A.flac
ā ā āāā Album A.cue
ā āāā Album B/
ā āāā Album B.flac
ā āāā Album B.cue
āāā Artist 2/
āāā Album C/
āāā Album C.flac
āāā Album C.cue
And process everything with a single command from the Music/ directory.
Before:
Album/
āāā Album Name.flac
āāā Album Name.cue
After:
Album/
āāā 01 - Opening Song.flac
āāā 02 - Second Song.flac
āāā 03 - Another Song.flac
āāā Album Name.flac.del
āāā Album Name.cue.del
- Non-destructive: Original files are renamed to
.del, not deleted - Skip protection: Won't re-process directories that already contain split song tracks
- Error handling: Reports failures and leaves originals untouched on errors
After verifying the split song tracks work correctly, you can remove the backup files:
find . -name "*.del" -delete
MIT License - see the script header for full details.
Issues and pull requests welcome! This script was created to solve a common problem in digital music archiving and is compatible with FLAC+CUE files created by EAC, dBpoweramp, Whipper, Rip Station, and other popular ripping software.
cue2tracks.shflac_album_splitter.shsplit_cue_flac.sh
The current name split_flac.sh was chosen for simplicity and clarity.
We have occasionally seen recordings consisting of .wv/.cue pairs (WavPack). This script currently does not split these. However, the underlying 'shntool' command that we are using supports the .wv format as well. The script could be modified to support .wv extensions, and the WavPack codecs can be installed with 'sudo apt-get install wavpack'.