Sorting Directories on FAT File Systems

Sort files in FAT file system directories

I have a car stereo in which I can plug a USB stick and play music or audio book files. It handles MP3, OGG, FLAC, and so on, so it's great that way. Newer vehicles let you play music from your phone, but I have no music on my phone, so that's not something I use. However, the software on the stereo that reads the files off the USB stick does not sort the files. If the tracks are copied onto the USB stick in order 10, 3, 8, 1, 4, 9, 7, 5, 8, 6, 2, then that is the order they will be played (unless using shuffle mode, in which case the original order does not matter).

Note that this technique applies only to FAT (FAT-32, VFAT) file systems.

To sort the files, I copy the MP3 files I want into a directory on the USB stick, and then run this script:

#!/bin/bash
#
#  Sort files alphabetically in the current directory.

FILES=()

for FILE in *; do
    FILES+=("${FILE}")
done

TEMPDIR=$(mktemp -d work_XXXXXXX)

echo ${#FILES[@]} files
for FILE in "${FILES[@]}"; do
    mv "${FILE}" "${TEMPDIR}"
done

for FILE in "${TEMPDIR}"/*; do
    mv "${FILE}" .
done


rmdir ${TEMPDIR}

I have this script, named sort-dir, in my PATH, so I type:

cd /media/usb/ARTIST/ALBUM
sort-dir

and now that directory is sorted and plays in-order on my car stereo.

Back when I wrote this script, I looked around for FAT file system directory sorters, and there a variety out there, some commercial offerings, but this tool does the job simply, quickly, and reliably.


Finding Files in a Relative Time Range

How to use the find command to locate files modified in a relative range of days

The find command allows you to find files within a range of dates. For example, let's say you wish to find all files modified in the past month, and show the file's size, modification date, and pathname. Use this: find . -type f -mtime -31 -printf '%10s %TY-%Tm-%Td %P\n' Each flag is described here: -type f: restricts results to plain files; no directories or links -mtime 31: restricts results to files less than 31 days old -printf '%10s %TY-%Tm-%Td...

Read More
Debian Packages: Finding Modified Files

Find and show modified .deb files

You have an installed package and you would like to see the if any of its installed files have been changed. If there are changes, you would like to see the differences. Verify Package The solution to finding modified package files is the dpkg -V *PACKAGE_NAME* command. It lists any files whose md5sums do not match those in the package metadata. Example: $ dpkg -V minidlna ??5?????? c /etc/minidlna.conf Show Differences in Modified Package...

Read More
Swapping CapsLock and LeftCtrl

Reconfiguring the CapsLock key

Some folks prefer the Left Control key just to the left of the A key on their keyboards. If this is you, read on. Linux If you are the only user of your machine, you can edit /etc/default/keyboard and add or change the XKBOPTIONS line so it reads as: XKBOPTIONS="ctrl:swapcaps" [I don't think this affects X sessions, so there is more to do.] XFCE4 If you share your machine with others, change the keyboard mapping in your own account....

Read More
Odroid-C2 Media Server

Set Up a Home Media Server on a Small Computer

An Odroid-C2 single-board computer makes a decent home media server. It has gigabit ethernet, it runs Linux, and it's faster than a Raspberry Pi. The Odroid-C2 has the ability to display 4K video and I am hoping to actually have this machine play movies out to the TV. So far, that part is not working. What does work, however, is serving media to the Xbox 360, iPads, phones, and other computers. This it does without a hitch. Operating System There are at...

Read More

Receive Updates

ATOM

Contacts