I’m trying to write a command for mplayer that will play all the music files in a directory, in order.
alias mplay='mplayer -playlist <(find "$PWD" -type f|sort -n)'
This works fine if I am already in the directory I’m playing music from. In fact, it even works if I’m in a directory back and I type ‘mplay MusicFileDirectory’ for instance.
However, the command breaks when I’m not in the directory I play from and the files are numbered 1, 2, 3 … 10, 11 etc (instead of 01, 02 … 11) – the 10, 11 files are now played before the 2nd file.
This is because sort is being applied to an expanded file path, ie MusicFileDirectory/1, so it does not sort numerically.
How would I get the sort command to only sort the final part of a file path, so I can type ‘mplay /home/james/Music/MusicFileDirectory’ for example and it only uses the names of the files in the directory to sort the playlist?
I’m not 100% sure it will work, but give sort -V a try.
EDIT: As jordanm notes, this is apparantly a newer GNU extension.