9.1 Audio Filenames

20190818 An audio collection can be maintained using a very structured format for the folder hierarchy and filenames. A suggestion is:


All names are lower case and the year is four digits whilst the track is two digits. In this way the database of audio is maintained ordered by the artist. Within the artist’s folder their albums are ordered chronologically. The individual tracks are then ordered numerically.

The scheme uses underscore everywhere rather than hyphens. The initial number (year or track) of the file name is always readily recognisable and hence separating it from the title with an underscore does not introduce any ambiguity. An underscore is more consistent and generally automatic.

The rename command introduced in Chapter @ref(command_line_tools) is very helpful in renaming files. It makes considerable use of regular expressions. As a simple example, hyphens in a filename can be readily substituted by underscore globally across the file name using:

$ rename -v 's|-|_|g' *

The -v turns on verbose mode so that the actions taken can be observed.

The rename command is a powerfull tool and the following may be useful, but represent just a starting point:

$ rename -v 's|(^.*)|\L$1|' *         # To lowercase.
$ rename -v 's| |_|g' *               # Replace spaces.
$ rename -v 's|_-_|_|' *              # A common pattern to fix in song names.
$ rename -v 's|&|and|g' *             # Expand the symbol.
$ rename -v 's|^(\d\d)-|$1_|' *       # Replace 01-paradise.mp3 with 01_paradise.mp3
$ rename -v "s|[~]|_|g" *             # Replace miscellaneous characters.
$ rename -v 's|\.\.+|_|g' *           # Remove multiple periods.
$ rename -v 's|_+|_|g' *              # Remove multiple underscore.
$ rename -v "s|['\(\)\[\]\`,\!]||g" * # Remove unwanted characters.
$ rename -v 's|_roger_watson||' *     # Remove common strings.

Your donation will support ongoing development and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.