Ubuntu – Sort files on the filesystem

clipboarddirectoryfilesmp3-playernautilus

My MP3 player plays files in the order they have been placed onto the filesystem. Now it seems to Nautilus copies files in some random order, so when listening to an audio book or something I get all the chapters in random order, wich isn't so great when your on a bicycle so you can't take your MP3 player out of your pocket to find the right one. When using mc (Midnight Commander) most files are copies in alphabetical order, and that's the way I want it to happen.

So is there…

  • any way to tell Nautilus to copy files and folders in alphabetical order?
  • a program wich can sort the files and folders in alphabetical order directly on the filesystem?

Additional information:

Best Answer

To embellish the answer by enzotib ; these players play files in the order they find them in the File Allocation Table (the FAT, in FAT).

FATSort is therefore one potential solution to the problem. The noted warning is for 2 reasons ;

  • The tool edits the file allocation table right at the bare metal level
    • It moves the file entries around within the confines of the directory table, so a corrupt filesystem will be more broken than it was before
    • As long as the filesystem passes a fsck.vfat check, you should be fine.
  • The author appears to feel that he hasn't devoted enough time to making his code secure
    • Potentially, you could create a (broken) file allocation table that caused a buffer overrun or similar problem in the FATSort application
    • In reality, this is unlikely - it's something of a niche application, the opportunities for an attacker to place a specially crafted file system on your MP3 player are limited, and if he had such an opportunity, there are much softer targets he'd go after first
    • Again, if your filesystem passes fsck.vfat (or a disk check in Windows), you should be fine - this is a belt-and-braces disclaimer by the author

palimpsest / Disk Utility has options to do a disk check from the GUI.

Other programs that sort the FAT can be seen here : http://www.murraymoffatt.com/software-problem-0010.html

Alternate solutions ;

Copy files in the play order

The simplest and most obvious is to copy the files to the player in the order which you wish them to play. Nautilus copies files in an apparently indeterminate order to the player file system for much the same reason - it tends to operate on files in the order the iNodes are arranged on disk.

If your track file names have the track number at the beginning, this is ideal. Most of the command line tools will sort things in lexicographic order. As you note, tools like Midnight Commander will also do this.

# Find the files in the source     | copy them to the target folder
# Note we use the          -print0 |       -0   args because media file names
# commonly contain spaces

find /path/to/music/folder -print0 | xargs -0 cp -t /path/to/target/folder

Create a playlist

Some players support playlist files. I keep scripts in my MP3 player filesystem to support generating these playlists. My player is an iRiver device, which has a specific binary playlist format. If your player supports .m3u playlists, the format is extremely simple, and just consists of commented metadata and paths in a text file. I used to make playlists in Rhythmbox and transform them to the iRiver format ; I've not had occasion to make one using Banshee yet (I only make them for workout purposes and my workouts are very predictable...)

Related Question