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

Meaning is not something you stumble across, like the answer to a riddle or the prize in a treasure hunt. Meaning is something you build into your life. You build it out of your own past, out of your affections and loyalties, out of the experience of humankind as it is passed on to you, out of your own talent and understanding, out of the things you believe in, out of the things and people you love, out of the values for which you are willing to sacrifice something. The ingredients are there. You are the only one who can put them together into that unique pattern that will be your life. Let it be a life that has dignity and meaning for you. If it does, then the particular balance of success or failure is of less account.

—John Gardner