Cinematically Kubular

Ramblings about cinema – probably focusing on Argento and gender.


Simple Batch Renaming or Renaming a Large Number of Similarily Named Files Very Easily

Off topic a bit, not that I’ve gone off films – I just haven’t watched any that have inspired me to write anything worth uploading in a while. Anyway, this one’s on batch renaming in Linux – specifically Fedora 18.

So, I know I’m not alone in occasionally finding myself with a directory of full of files that have a lot of similar names that for one reason or another are a hassle when being used in a specific way. For me this happens most with videos I watch via my TV. But it could just as easily relate to chat logs, music files or photo archives.

Maybe you have a lot of mp3s named Artist – Title – #.mp3 and for some reason you need to remove all the spaces for compatibility with a specific application or device. It’s a hassle to go through hundreds of tracks manually deleting every space.

Fortunately, util-linux has a utility for that! For some this is preinstalled, if not, the util-linux package should be available in your distribution’s standard repositories. If you’re unsure, it’s easy enough to find out, open a terminal session and type the following command:-

$ rename -V

I receive the following output:-

rename from util-linux 2.22.2

-V (uppercase V) is the option to return the version number of the program, -v (lowercase V) tells the program to run in ‘verbose’ mode, meaning it’ll print to the terminal anything it does – this is useful if you want to make sure you know what a program’s actually done. So my installed version of rename is from the util-linux package version 2.22.2

My first instinct when using any terminal application for the first time (and tbh, most gui apps) is to check for a man page. Manpages is one of the most useful Linux applications available, is run from the command line and usually (I believe) installed by default by most distros. The syntax to check if a program has a man page or not just type

$ man <program name>

into a free terminal session, if it does, this’ll bring the page straight up and most follow a quite logical and standard format that lists the various options available when executing a program and how to use them.

Unfortunately, rename’s manpage is a little unclear – especially if you’ve already googled and found various bash scripts to rename large numbers of files. If you have rename installed, writing a whole bash script is likely unnecessary. However, be warned, rename is both extremely powerful and also without any safeguards, it will not ask you before it starts overwriting or deleting files. Also, the manpage does not cover the full capabilities of the program, as I accidently discovered! So be careful about using wildcards (such as *) or other special characters in your arguments.

If you are intending to use any utility to automate the renaming of a large number of files, I would always encourage anyone to test it first on some ‘fake’ or unimportant data. It’s worth creating a test directory with some empty files in and mucking about with those before you start renaming files you actually care about. Chances are it’ll save you time in the long run.

So where was I? Oh yes, we have a bunch of files to rename. Let’s pretend we’re an avid photographer who’s been storing our photos on a shared computer and we’ve been using the following convention for our files:

ourname.filedescription<number of photo in series>.cameramodel.raw

So a typical photo directory might be full of files looking like this:


all the way up to


Now, we’ve moved the files onto our own home computer, we know we were the photographer, so we no longer require the prefix and the camera model is held in the metadata anyway, so that’s also redundant. The only part of the file name we’re interested in is the Party999 section and the file extension. If we were to rename all 999 files it’d take us an hour, probably and we’d end up with very sore wrists. This is where rename comes in handy.

Rename uses the following syntax:-

rename [options] string to be changed replacement string string to select files to act on

I’ve tried to explain the command in plain english, which for me seems really confusing, the man page however, describes it like this:

rename [options] expression replacement file...

So how do we rename our photos? Well, I’d do it in 2 steps, like this:-

$ rename JohnSmith.Party Party *.raw
$ rename OlympusBlah.raw raw *.raw

The first step above tells rename to select any files that end in .raw and change any instances of JohnSmith.Party to Party. Effectively removing the JohnSmith prefix.

The second step does the same thing. Selects all files that end in .raw, removes any instance of OlympusBlah.raw and replaces it with raw. Because we’ve left the 001. part untouched, the raw extension will just be appended to that and our filenames will appear as expected:-


and so forth.

This way we ignore the part of the filename that contains the unique identifier, such as 001, 002, etc and only operate on the parts of the strings we know are constant. This is important because it removes the need to use special characters such as * and occidentally tell rename to do something unexpected. Which was a trap I fell into, and started renaming files with the filename next in the list. I don’t fully understand why rename did this, or how the command was working, so I won’t go into it here. It’s just good practice to try and operate only on known constants, where possible. Unless of course you really know what you’re doing. 😉

So anyway, with just two terminal commands we’ve renamed 999 files, there’s no way we could have done that manually without a lot of effort and time.

There are GUI applications out there that I’ve heard of that are supposed to be very powerful, while reading up I read that there’s a KDE application called Krename available. However, I can’t imagine a GUI interface being more efficient, especially when the rename utility is that simple to use.

Happy renaming!

Employee Relations, the Mac Community and Free & Open Source Software

Yeah I know – this blog is supposed to journal my adventures in cinema (or rather, lovefilm). I haven’t posted for a few weeks now – mostly because I haven’t really been watching all that much. I was, for better or for worse, also made redundant. The upside to that was that I recieved a small redundancy payment and spent a few weeks researching and purchasing parts to upgrade my main PC. I also thought this would be a good opportunity to format my drives and perform a clean install of both Windows and Ubuntu (which were then my main Operating Systems).

For the most part everything went swimmingly. I can testify that yes, Solid State Drives really are that fast. It’s amazing how much of a bottleneck Hard Disk Drives really are in modern systems. I used to dual boot Windows and Ubuntu mainly because Windows was so slow that I couldn’t be bothered to use it for normal everyday tasks such as web browsing, blog posting and the odd bit of network maintenance. 

Now, those that know me will probably be aware that I use a MacBook – which I’ve owned since 2007. I love my MacBook and for a few years it was the go-to machine for ‘lightweight’ general tasks. Windows was purely for playing games – and that was only because I had no other real choice. Unfortunately, over the years my MacBook has gotten very slow… mainly because I had over 75GB of data on an 80GB HDD and because OSX releases have gotten gradually more demanding on the system specs. 

This meant that, like Winblows, OSX was becoming a bit of a frustration. It was taking just as long to load the OS and I was having to spend time waiting for programs like Firefox to actually be read from the HDD before I could use them. The upside was that, as a laptop, I could sit with it in the living room and browse the net while still listening to music or enjoying the sunshine.

My experience on the PC was leading me to feel that Linux was much more efficient and much better suited to my needs. However, I was also wary of the more powerful processor and significantly larger amount of RAM that I had in there, so I still wasn’t quite ready to leave OSX and try replacing it with Ubuntu.

I bought my MacBook for several reasons – firstly, I was sick of Windows and wanted something as useful as Linux but that actually worked. The second was that the MacBooks had much better key spacing than the keyboards on Dell, HP and Samsung portables available at the time. The third was that actually, from what I’d seen, OSX had a really nice User Interface. It still does.

I was put off by the Apple logo on the top cover though, after all, I didn’t really want to advertise myself as an Apple fanboy or one of those types of people with the white earphones. I wanted an Apple computer because they’re good computers. I decided that this was a small price to pay though, and now quite happily enjoy sitting in my darkened living room typing out rants for publishing on the internet.

In the last few years Apple have been extremely successful with the iPhone and iPad products. They’re not really my cup of tea, but I can appreciate why other people like them. And as expensive as Apple products may be they are very well built. The iPad may be heavy but it is solid and that counts for a lot. And to push the point a little further… I’ve had my MacBook for 5 years, I’m still using it and the only things I’ve had to do to it (other than software updates) have been to replace the battery and swap the 80GB HDD for a 256GB SSD. The battery I was extremely lucky with – the Apple Store replaced that for free (and even they didn’t know why I wasn’t being charged for it).

Replacing the HDD with a SSD was a huge upgrade, I now have little to no waiting time when launching applications and the OS is actually usable even while it’s loading my various startup apps. It’s given my MacBook the extension of life it needed. However, it’s brought back a frustration that has been with me for a few years now – the lack of focus follows mouse support, specifically auto focus.

I remember years ago (I think while I was still at uni) I read one of Linus Torvalds’ open letters (or was it a forum post?) regarding user interface design with gnome… or something. In it was a reference to focus follows mouse, and how it was the only way to use the mouse that he felt made sense. I’d never heard of focus follows mouse at the time – and even thought it sounded kinda weird but the sentiment stuck with me, and sure enough I found myself thinking back to it a few years later.

I’d reached a stage where the act of clicking was beginning to frustrate me – why was it necessary? I was finding myself just looking at windows and trying to type into them, forgetting that I actually needed to express which task I was trying to accomplish to the computer. Sure enough, with a little help from google I found a way to configure Ubuntu to use ‘sloppy’ focus. That is, to automatically raise a window when the mouse hovered over it. To many this is possibly the worst mouse interface paradigm possible, to me, not so much. After all, I’d already made the move to dual monitors and had plenty of screen real estate, overlapping/stacking windows wasn’t really the issue for me, it was just to get away from that awful clicking action. I very quickly got used to it, I was suprised by just how right focus follows mouse felt – even with the automatically raising windows. Since the computer doesn’t know how to track where your eyes are looking – then it seems logical that tracking the mouse pointer is the next best thing.

Over time my tastes refined, and I found myself moving away from auto raise to auto focus.. it’s a much more elegant setup and allows for typing into/interacting with windows without actually bringing them to the front. This is helpful when you’re keeping an eye on a terminal output, or chatting to a friend while you’re browsing the web. Or, particularly, when you’re researching how to perform a command line task (such as batch file renaming) and you want to interact with the terminal at the same time as reading your browser.

But I can’t possibly emphasise enough how it’s the mere act of clicking that is the real problem. I swap between application windows quite frequently, I often have an IRC client, an Instant Messaging client, a web browser, an e-mail reader and a terminal session running whenever I’m on either OSX or Linux. That encourages a lot of clicking about – a lot of energy expended and a lot of hearing that awful noise.




So, today I googled how to get focus follows mouse working on OSX. Guess what? You can’t. I was suprised by that, partly because even Windows now supports focus follows mouse – in Windblows 7 it’s actually available in the accessibility options. Admittedly, the GUI menu only allows for autoraise functionality but it is possible to configure further in the registry (though I’ve not bothered trying yet – two monitors).

In OSX, the function simply isnt there. Now, I don’t know if the situation has changed since Leopard, but it used to be impossible even to code. Supposedly because of the way OSX is designed. What really gets to me though, is the attitude of other users when reading about it in blogs or forums. Whenever anyone makes a post about focus follows mouse and how much they miss it/want to get it working, there’s a bunch of Mac fan boys that jump in trying to tell the poster that they don’t really want that feature.. OSX has many alternative ways of switching focus between applications… and so forth. I’ve even seen it referred to as a feature that it isn’t included. How is the lack of a more efficient mouse interaction model a feature? Oh, wait… Apple made OSX, therefore it must be right.

Though, I’m being unfair, and this is the main reason I felt motivated to write this blog post. This is not a behaviour specific to Apple fanboys, rather the opposite, it’s a behaviour specific to people (see what I did there?). People always find ways of justifying or defending flaws in something that they feel somehow attatched to. When someone spots a weakness or problem in a system/process and tries to bring to the attention of someone else, often the first response is often one of defence. In some ways it’s natural, after all, we have to challenge an idea to test it’s strength. But there’s a limit to that, and often the idea of actually having to go to some effort to impliment a change, or see a change take place to something that you regard as perfect can outweigh the desire to listen to and respect other people’s needs, desires and expectations of a system. We tend to call people that don’t behave in this way free thinkers.

The use of the word ‘free’ in the term ‘free thinker’ matches the usage in the Free & Open Source Software (FOSS) movement. It’s that aspect of freedom that makes FOSS so attractive, wether it be Free BSD, Linux, Gnome or KDE. Whenver I’ve had a problem with a Linux distro, wether it be Ubuntu or Fedora, I’ve always been able to request help on a forum, or google for solutions. And there’s always a group of people eager to help. Granted, they don’t always understand the problem right away, and there’s often a sense of dissapointment (and almost resentment) from someone who’s invested time in trying to explain how to solve a problem, just to find out it’s not actually the problem you have. But there’s almost always a way to get things to work the way you want, or to request they be changed so that they can in future. What I’m trying to say is, there’s a real sense of community in the Linux/FOSS world. People really want to help, where possible.

I’ve always been a believer that most people feel like this anyway, that they do want to help, they just can’t – wether it be their own fear or failure to understand that’s blocking them. Well, I used to be. Now I’m not so sure that’s true. I still believe that most people want to help, at least, good people do. That’s the difference between a good person and a bad person – do they want to help?

The same can be said about employers. The difference between a good employer (or manager) and a bad one is their willingness to listen to and support their staff. It’s possible to try and do the ‘right’ thing and be ‘fair’ to your employees, but without a good channel of communication, or a willingness to listen, it doesn’t mean anything. It’s for this reason that I’m a strong believer in Trade Unions. Because a good union works with the employer, to communicate the wishes and needs of the staff, while ensuring a fair deal for both sides. It makes no sense for a union to attack or be aggressive towards the employer… after all, if the business can’t make money it can’t be successful, and then there won’t be any jobs to keep staff in. A good union doesn’t strike every time terms and conditions change. A good union looks at ways to make sure those terms and conditions change only as much as they have to and in the best and fairest way possible – with reaistic consultation of the staff.

It’s in this way that Unions are a bit like the open source community, they listen to the desires/ideas of the users and look for ways that they can be implemented. If a feature is to be dropped/not taken forward, there’s always someone willing to explain why not – and if you’re willing to listen, it usually makes sense. Sometimes things are just out of scope at the time they’re suggested, and a few years have to go by before the direction of the project matches that of the suggestion. This happens a lot in the workplace too.

I went to a job interview not long before being made redundant, during which I was repeatedly told that they weren’t a “communist company”. I still have no idea what that means. I mean, they were a profitable software developer/financial services company… I wasn’t expecting all their profits to go to cancer research or anything. The only way I have ever managed to interpret that phrase is that “we/the owners/partners are greedy bastards who just want to make as much money as possible while exploiting as many others as necessary to do all the work for us”. That’s a very old philosophy/approach to business, and it’s what brought about the birth of Trade Unions in the first place. I’m exagerating slightly, because the representative of the company I was being interviewed for also seemed to have his head on straight, and acknowledged that he does try to do the best by his staff “if you do right by us, we’ll do right by you.” I can’t complain at that kind of attitude.. as long as they’re willing to listen to what right is. And that’s where we come back to OSX.

All these Apple fanboys (and probably apple themselves) believe that because they’ve designed OSX to behave a particularly way that it should behave in that particular way. Now, I’m sure they do plenty market research, with focus groups and all sorts. But that won’t necessarily bring about new ideas. After all, I’ve never seen focus follows mouse as a default option, even in the various Linux distros I’ve tried. It’s always required me to go hunting for it. And KDE is the only desktop environment I’ve ever found a graphical menu item to actually configure it properly. Bearing in mind how sensible focus follows mouse seems once you start using it, I’d be suprised if a new computer user wouldn’t pick it up right away. If it was then switched off would they find it an improvement to have to start clicking windows to give them focus? I doubt it. I never have. Yet all those Apple fanboys rant and rave about how OSX is designed not  to support it. It probably seems perfectly sensible to them to find workarounds, and suggest keyboard ‘shortcuts’ or alternatives, but alternatives aren’t what we want. As long as mouse cursors are the standard in graphical interface design, focus follows mouse is what we really want and we want it because it’s a good idea.

Anyway, I have no idea what the word count is on this but it’s probably enormous, so I’m going to stop there. I might come back and stick in some pics of Tux later if I can find some good ones. 😉

I hope you’ve all had a merry christmas and that you have a happy new year tomorrow too. 🙂