Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My car can read MP3 files from a FAT32 flash drive. I have a folder for each artist on the drive, then MP3 files in those folders.

However the car does not read the folders alphabetically, but by the order they were added to the drive. I can use DriveSort to sort the drive after I add a new artist. Could this "sorting" be done from the command line, perhaps using touch?

share|improve this question
touch won't work because it is nothing to do with timestamps. –  goldilocks Dec 31 '12 at 19:17

2 Answers 2

up vote 3 down vote accepted

Depending on what OS you are using there are command line utilities such as:

And touch won't help you with sort since all you will be able to do with it is manipulate the timestamps on the file or directories.

share|improve this answer

I think Linux's FAT32 driver fills directory entries in the order they're created, so all you have to do is add the files in the order they're wanted. If you want to insert a file in the middle, move everything to a temporary directory and then back. If you want alphabetical order, it's easily done from the shell, since wildcards expand to a list sorted in alphabetical order.

mkdir tmp
mv * tmp      # ignore the complaint about not being able to move tmp as a subdirectory of itself
mv tmp/* .
rmdir tmp

If you want to do this to the contents of every directory on the drive:

cd /media/sdcard
mkdir tmp
find . -path ./tmp -prune -o -type d -exec sh -c '
  mv "$0"/* tmp
  mv tmp/* "$0"
' {} \;
share|improve this answer
I tried this. It did reorder them, but still not alphabetical. –  Steven Penny Dec 31 '12 at 23:24
@svnpenn Ah, it did when I tested it. Does it help if you remove the source directory and re-create it? (That won't do for the root directory, unfortunately.) –  Gilles Dec 31 '12 at 23:35
I suggest (1) adding a -type d to the find command (after the -o) to avoid getting mv: ./Beatles/Hey_Jude.mp3/*: Not a directory, mv: ./Beatles/Yesterday.mp3/*: Not a directory, etc., and (2) changing "$0/*" to "$0"/* (in the first mv command) so it will work and not throw mv: ./Beatles/*: No such file or directory errors. –  Scott Mar 12 '13 at 1:50

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.