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.”
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.
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 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:
When you’re ready, click “Rename” and all of the characters prior to the first space will be wiped out:
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.