I've got a USB drive with mp3 music on it that I play in my car. My car has a USB drive port. Problem is that the car sorts the music by Creation/Modification Date (and not alphabetically). This makes it a pain to find what artist I'm looking for.
To solve this problem, I need a way to "update" the Creation/Modification Date for all folders on the USB drive every time I add a new folder of music to the USB drive. Anyone know how I can do this?
The Touch command works great, but the format touch <filename>
would take forever to do on each folder on the drive. Anyway to select all folders on the drive and then touch <all folders>
?
On my USB drive I have a folder for each album and the songs within each respective folder, like so: Album-1-folder Album-2-folder
I need to apply the Touch command to each of the "album" folders on the drive.
I stumbled upon a simple solution to solve this issue:touch /media/USB_Drive/*
If you have a lot of files to touch, it's just going to take a while. You can plug-in the drive, and in a terminal, assuming your drive is mounted as
/media/USB_DISK
, do the following:Just replace the
USB_DISK
with the proper name of the folder where your drive is mounted under the/media/
directory.Even if you get that to work, all files would have the same date. It doesn't sound like that would help.
What would work is a script that has hard-coded file names. Hard-coding the file names is necessary to create your preferred order. Just "touching" them in the preferred order will "create" your order, so you don't need to enter actual dates into the touch command.
The "sleep" commands are needed to force each "touch" to have a different time. Note that the file "numbers" don't matter, and are processed out of numerical order. The order in the script, however, creates the "processing" order.
Note that you will need to update and run your script every time you add new songs/files.
Edit: I just saw the "sorted find" post. That would probably work better. :)
Dobey's answer is on the right track, but it will fail if any directory name contains a space. In general, it's not a good idea to use the output of
find
in a script for the same reason that the output ofls
shouldn't be parsed by a script: File names can easily contain characters which make it difficult or impossible for a script to accurately interpret.There are several options here. One is to use the
-print0
switch tofind
combined with an appropriate call toxargs
. See the respectiveman
pages for details.The approach I'm recommending is simpler for the specific problem at hand and uses shell globing to get accurate file names:
Note that using a glob automatically results in an alphabetized list.