Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7459043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:56:16+00:00 2026-05-29T13:56:16+00:00

Now before you face palm and click on duplicate entry or the like, read

  • 0

Now before you face palm and click on duplicate entry or the like, read on, this question is both Theory and practical.

From the title it is pretty obvious what I am trying to do, find some files, then rename them. Well the problem, there is so many way to do this, that I finally decided to pick one, and try to figure it out, theoretically.

Let me set the stage:
Lets say I have 100 files all named like this Image_200x200_nnn_AlphaChars.jpg, where the nnn is a incremental number and AlphaChars ie:

Image_200x200_001_BlueHat.jpg
Image_200x200_002_RedHat.jpg
...
Image_200x200_100_MyCat.jpg

Enter the stage find. Now with a simple one liner I can find all the image files in this directory.(Not sure how to do this case insensitive)

find . -type f -name "*.jpg"

Enter the stage rename. On it’s own, rename expect you to do the following:

rename <search> <replace> <haystack>

When I try to combine the two with -print0 and xargs and some regular expressions I get stuck, and I am almost sure it’s because rename is looking for the haystack or the search part… (Please do explain if you understand what happens after the pipe)

find . -type f -name "*.jpg" -print0 | xargs -0 rename "s/Image_200x200_(\d{3})/img/"

So the goal is to get the find to give rename the original image name, and replace everything before the last underscore with img

Yes I know that duplicates will give a problem, and yes I know that spaces in the name will also make my life hell, and don’t even start with sub directories and the like. To keep it simple, we are talking about a single directory, and all filename are unique and without special characters.

I need to understand the fundamental basics, before getting to the hardcore stuff. Anybody out there feel like helping?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:56:17+00:00Added an answer on May 29, 2026 at 1:56 pm

    Another approach is to avoid using rename — bash is capable enough:

    find ... -print0 | while read -r -d '' filename; do
      mv "$filename" "img_${filename##*_}"
    done
    

    the ##*_ part remove all leading characters up to and including the last underscore from the value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this get ever more complicated :) now i face another issue in last question
Now before people start marking this a dup, I've read all the following, none
Third try at fixing this tonight - trying a different approach than before now.
Now before At the risk of getting this subject closed I just need to
I've already read this but it doesn't answer to my question. Here's my scenario:
Obviously I can do and DateTime.Now.After - DateTime.Now.Before but there must be something more
I'm a hobbyist programmer (only in TI-Basic before now), and after much, much, much
I've never used Java AWT before and now I've got a piece of code
I haven't done much multithreading before and now find the need to do some
Now, before you say it: I did Google and my hbm.xml file is an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.