How To: Simply Convert A Directory of FLAC files to MP3 with FFMPEG in Linux

Stick the following in a file called flac2mp3 or such, chmod +x it, then put it in somewhere like /usr/local/bin

To use it, simply go to your folder of .flac files and run flac2mp3, then perhaps rm *.flac to get rid of the (massive) flac files you don’t want anymore.

How-To: Replace characters in filenames in Linux

Occassionally you’re likely to end up with a bunch of files with filenames that are underscore separated or space separated when you want them the other way around, and then you either have to manually rename them by hand, or live with it.

I had this issue the other day so I wrote a script to convert all filenames in the current directory to the specified format.

The script switches are:

  • -t – turns on [T]esting mode, which displays what would happen if you ran the script, but makes absolutely no changes to filenames.
  • -u – converts all [U]nderscores to spaces.
  • -s – converts all [S]paces to underscores.
  • -l – converts all filenames to [L]owercase.
  • -p – converts all filenames to u[P]percase.

It’d be nice if I could get all working recusively and offer an option to Capitalise Each Word in the filenames, but this will do for now.


Like most scripting, this entire thing could probably be done in a single line, but I found it useful to learn how to use getopts and such.

Hope someone else finds it useful! Oh, and if you need a do-everything file renaming script, I read that FixNames script does what it says on the tin.

How to: Get absolute/relative file paths, filenames and extensions from a Bash script

I’ve been learning some Qt stuff today, and the resulting code requires pre-processing of header files to work correctly, which I thought I’d try to automate. As part of this, I needed to find out how to get at all the different elements of a file from a bash script, so I did some googling and got all the info I needed :)

The script itself isn’t particularly useful, but the component parts of how to get at paths, extensions, and plain filenames without extensions definitely is – check it out:

fileParts Shell Script

I created two dummy “.h” files in my home folder and ran the script – this is what it outputs:

That’s gotta come in useful, right? =D

How To: Remove all desktop.ini (or indeed any recurring) files in Linux

I spent a while going through my music hive today, just putting music I’d ripped and dumped into the New folder into the correct spot, placing all albums by the same band into a folder called the band name etc, and there’s a hella lot of desktop.ini and Thumbs.db files floating around. This might be useful for people running Windows, but I’m not (or at least not anymore, and not for a long, long time) – so lets be rid of them, shall we?

Blatantly Unnecessary Warning: Deleting files deletes files! Fo’ real, yo! So try out the “tester” script before unconditionally deleting things you might now want to! =D

Measure Twice, Cut Once

Before we delete files en masse – let’s check to see what files we’re opting to remove. To do this, and assuming we want to check what desktop.ini files we can remove, just enter something along the lines of the following into the bash:

For example, if my music is stored on my NAS at /mnt/Share/_Serva, then to check what files will be removed, I’ll enter:

After hitting return on the above, you should be given a list of instances of files called desktop.ini and we get to put our minds at ease that it’s not even thinking about adding any other files (such as mp3s or what-have-you) to the list.

Cease and Desist

Once we’re happy we’re going to remove only the files we want gone, to interactively delete all the desktop.ini files from a given folder and any subfolders (and by interactively, I mean it’ll ask you whether you want to delete each one), enter the following command into the bash:

So in my instance, to interactively (i.e. I’d then have to confirm each delete) remove all instances of desktop.ini, I’d enter:

If I wanted to automatically remove all copies of files named desktop.ini without confirming each deletion, then I can just strip off the -i switch, leaving:

You can then do the same thing for Thumbs.db or any other filename just by substituting the appropriate details after the -name switch.

Done & done =D

P.S. Just for the record, removing the -i will make the deletion occur automatically unless the file is write-protected, but you can always sudo that away, just like the request for a sandwich.

Credits & thanks: MegaJim over on Ubuntu Forums.

How To: Convert a Directory of MP3s to WAVs in Linux

I went to burn a couple of audio CDs for the boy today, and bod-frickn-dammit if Brasero / GnomeBaker and K3B didn’t all threw their hands in the air in dismay that I might actually have the nerve to want to convert mp3s to CD-audio on the fly. Very poor.

So, as wav files come in less flavours than mp3s and tend to work first time, I knocked up a quick script to convert a directory of mp3s to .wav files using mpg123, it even handles spaces correctly after I’d given it a stern talking to… Anyways:

To use the script:
– Copy and paste the above code into a new text file called mp32wav or something
– Make it executable with chmod +x mp32wav, then
– Copy it to /usr/local/bin for easy access with sudo cp mp32wav /usr/local/bin/

With that all done you can just go into a folder of mp3s in the terminal and fire it off. It’ll create a folder called WAV inside whatever directory you’re in and stick the converted wav files there with the original filename but with .wav tacked on the end.

Cheers!