Go to TogaWare.com Home Page. GNU/Linux Desktop Survival Guide
by Graham Williams
Duck Duck Go

Audio Filenames

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

  <artist>/<year>_<album>/<track>_<title>.(flac|ogg|mp3)
  <artist>/<year>_<album>/cover.jpg

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

A useful command to remove unwanted characters like ', (, and ) can be similarly constructed:

$ rename -v "s|['\(\)]||g" *

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

$ rename -v 's| |_|g' *		        # Replace spaces.
$ rename -v 's|-|_|g' *           	# Replace dash.
$ rename -v 's|_+|_|g' *           	# Remove multiple underscore.
$ rename -v 's|(^.*)|\L$1|' *		# To lowercase.
$ rename -v 's|_roger_watson||' *  	# Remove common strings.
$ rename -v 's|^(\d\d)-|$1_|' *    	# Replace 01-paradise.mp3 with 01_paradise.mp3
  
$ rename -v "s|[!,\(\)\[\]\'\&]||g" *   # Remove miscellaneous characters.
$ rename -v "s|[~]|_|g" *               # Replace miscellaneous characters.

Copyright © 1995-2020 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware and the author of open source software including Rattle and wajig.
Also the author of Data Mining with Rattle and Essentials of Data Science.