journal features
movie reviews
photo of the day

renaming files containing a space from the Linux command line

the journal of Michael Werneburg

twenty-seven years and one 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

Briefly stated, the Gell-Mann Amnesia effect is as follows. You open the newspaper to an article on some subject you know well. In Murray's case, physics. In mine, show business. You read the article and see the journalist has absolutely no understanding of either the facts or the issues. Often, the article is so wrong it actually presents the story backward—reversing cause and effect. I call these the "wet streets cause rain" stories. Paper's full of them. In any case, you read with exasperation or amusement the multiple errors in a story, and then turn the page to national or international affairs, and read as if the rest of the newspaper was somehow more accurate about Palestine than the baloney you just read. You turn the page, and forget what you know.

—Michael Crichton