Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

share|improve this question
up vote 5 down vote accepted

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 :

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...)

share|improve this answer
Thanks for the extended answer! Does your script copy recursively (meaning that it takes subfolders with it)? I don't know whether my MP3 player supports playlists (haven't found the option anywhere in the device itself), and it's hard to find any information about it (Yoo Move 1801) as it's a rather unknown device and their whole website is in French. – RobinJ Nov 11 '11 at 14:29
Hmm... @Adrian? Your script only copies the files wich are inside the folders, throwing them all together in the target folder, destroying my folder structure (well, it doesn't take the folders with it, only the files inside them) :p Do you think you could fix that? :) – RobinJ Nov 11 '11 at 15:17
I have contacted the developer (who appears German) with better wording of that English disclaimer, and fixed other "usage" inconsistencies (removing "=", which break features). – kevinf Apr 15 at 19:55

The utility you look for exists, and is FATSort.

It is available in Ubuntu Repositories in the fatsort package.

share|improve this answer
I've already had a look at FATSort. Problem is, as I stated in the question, that the FAT32 filesystem on the MP3 player is a bit unusual. And FATSort states this: NOTE: THE FILESYSTEM MUST BE CONSISTENT, OTHERWISE YOU MAY DAMAGE IT! IF SOMEONE ELSE HAS ACCESS TO THE DEVICE HE MIGHT EXPLOIT FATSORT WITH A FORGED CORRUPT FILESYSTEM! USE THIS PROGRAM AT YOUR OWN RISK! – RobinJ Nov 11 '11 at 12:15
Consistent is a term windows used in Fat32, meaning the filesystem is free of errors. Simply do an fschk first. – kevinf Apr 15 at 19:56

It could be that the player uses the modification time of the file. You could use a python script like the following to get all files in a folder, and touch them to change the last access time. Without the player, I can't test the result of cause.

import os
import sys
path = sys.argv[1]
thefiles = os.listdir(path)
for fname in thefiles:
    os.utime(os.path.join(path, fname), None)

This script should be run on the player folder (replace "path_to_the_player_folder" with the actual path) like this (if you saved it as python "path_to_the_player_folder"

I have no idea on how to tell nautilus how to copy files. Others might answer that part of the question, though.

share|improve this answer
Only applications which display the files sort them in a way. << Well they have been placed on the filesystem in a specific (random) order :p I'm pretty sure ut hasn't got anything to do with the access time (as the order doesn't change when I play a file or anything, either on the computer or on the MP3 player itself). But I'll give it a try. – RobinJ Nov 11 '11 at 11:20
Well, atime (access time) and mtime (modification time) are different on most file systems. So changing the modification time might help (both are changed by the script). On the other hand, it was really just a guess that the time is used. The actual physical order within the files system seems highly unlikely to me as an odering criterion... – xubuntix Nov 11 '11 at 11:25
Files are places in the directory (which is a sort of metafile) in a given sequence, as returned by find. – enzotib Nov 11 '11 at 11:43
you are probably right. I will remove parts of the answer then. – xubuntix Nov 11 '11 at 11:45
IIRC these players play the files in the order they appear in the file allocation table. See ; – Adrian Nov 11 '11 at 13:23

Regarding fatsort, use it like this :

sudo umount /dev/sdxxxx
fatsort /dev/sdxxx

You need to figure out what dev it actually is - could be sda, sdb, etc.

sudo fdisk -l 

should show you the mounted systems.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.