journal features
movie reviews
photo of the day

renaming files containing a space from the Linux command line

the journal of Michael Werneburg

twenty-eight years and a million words

Kokubunji, 2022.10.16

Every year I make a book of photos from the kids' past year. It's my Christmas present to my parents and other family members. This means I'm managing a lot of photo files. Recently my wife's contributions come in the form of .heic files from her iPhone. For some reason my photo-editing software doesn't work well with .heic files so I use a converter to make .png or .jpg files.

Sadly, the converter inserts " conv" into the file name of its output. This introduces a space into the file name. Because my website CMS is designed around a certain file naming convention, I then have to remove the " conv" string from the names.

And that's where batch operations with Linux hit a snag. I've worked around the problem in a two-part script. The first script generates the second, so I run them like this:

./fix.sh > fixes.sh

./fixes.sh

Here are the contents of fix.sh:

#!/bin/bash

a=$(echo '*conv*') # remember this trick?

for b in $a

do

c="'$b'" # put single quotes around the name containing the space character

d=$(echo $b | sed 's/ conv//')

echo "mv $c $d"

done

rand()m quote

If I had my life to live over, I'd try to make more mistakes next time. I would relax, I would limber up, I would be crazier than I've been on this trip. I know very few things I'd take seriously any more. I'd certainly be less hygenic... I would take more chances, I would take more trips, I would scale more mountains, I would swim more rivers, and I would watch more sunsets. I would eat more ice cream and fewer beans. I would have more actual troubles and fewer imaginary ones. Oh, I've had my moments, and if I had to do it all over again, I'd have many more of them, in fact I'd try not to have anything else, just moments, one after another, instead of living so many years ahead of my day. If I had it to do all over again, I'd travel lighter, much lighter than I have. I would start barefoot earlier in the spring, and I'd stay that way later in the fall. And I would ride more merry-go-rounds, and catch more gold rings, and greet more people and pick more flowers and dance more often. If I had it to do all over again - but you see, I don't.

Jorge Luis Borges