Ryan and Debi & Toren

GPRENAME – removing text up to a space using regular expressions

For a recent project, I came into possession of hundreds of photos, each of which was named according to the settings the person who take the photo with their phone had in place but ended with ” – FirstName LastName.jpg.”

The photos have varied characters before the names. That required some creative thinking on how to batch rename them.

I wanted to keep the users’ names, but everything before that could go. With hundreds of photos, I realized that it would be way too time-consuming to edit each file name by hand. Enter “gprename,” an app for bulk renaming files in Linux, and regular expressions.

Regular expressions are strings of characters that can be used to search for patterns. I’m no expert, but I’m familiar with them and realized that this could be a solution to my problem. A quick google search brought up this Stack Overflow post with the answer. I then applied it using gprename and, a 2 hour task was cut down to 5 minutes.

Here’s how I did it…

Open gprename and navigate to the folder where the files are located.

This is one of about 14 folders I needed to clean up.

On the “Replace / Remove” tab, in the “Replace” box, enter: “^.*?\s+”. In the “with” box that follows, you can just leave that blank. Make sure you check the box next to “Regular expression.”

Here’s where you enter the regular expression.

Here’s what the expression means:
^: Match from the beginning of the line
.*?\s+: Match anything until a space is encountered

Hit “Preview” and you should see the result:

A preview of the changes.

When you’re ready, click “Rename” and all of the characters prior to the first space will be wiped out:

The cleaned up files.

In my case, I then did some additional renaming (removing the ” – ” before the names and adding dates after), but this should get you close to your goal.

Exit mobile version