Linux Bash: create a playlist with a small script
You want to add mp3 files to a playlist with the extension .m3u and wants to sort it. A lot of music player software uses the .m3u file format. It is an old file format.
History of the file format .m3u
It was created in 1996 by the Fraunhofer Institute (in German: Fraunhofer-Institut für Integrierte Schaltungen IIS) in Munich, Germany.
Onliner in Bash
If you don’t want to create a script, then you can it with a one-liner in the Bash.
find . -type f -name "*.mp3" -printf "%f\n" | sort > playlist.m3u
After find, the point marks the current directory. If you want to use another directory, then change the point into your current directory like /home/username/music
-type f only search for files (not folders)
-name search all files with the extension .mp3.
The advantage of a script
A script is more comfortable. You can add directly the name of the playlist and check whether there are mp3 in the current directory.
Here is the script
#!/bin/bash
clear
#the name of the playlist
echo -n "Give the playlist a name "
read abspielliste
#find the mp3 in the current directory
mp3files=$(find . -maxdepth 1 -name "*.mp3")
#checking whether there are mp3 files in the current directory
if [ -n "$mp3files" ]; then
#generate a playlist in m3u
echo "Playlist will be generated in the current directory"
find . -type f -name "*.mp3" | sort > ${abspielliste}.m3u
else
echo "No mp3 files found"
fi