Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have files with filenames such as this:


I'd like to replace that with just:


Is there any way to do this in batch, automatically?

Note that some files have different words before and after the underscore so I can't just strip the first part of the filename.

(PowerShell, Terminal, or any free 3rd party tool is fine...)

share|improve this question
It would be helpful if you said what system you are running. – Scott Nov 16 '12 at 17:48
Windows, but I have access to Linux, if necessary. – Philip Seyfi Nov 16 '12 at 19:17

Since you mention “batch” and “PowerShell”, I guess you’re running Windows.  I doubt that ordinary Windows batch can handle this, and I don’t know PowerShell.  However, this question is essentially the same question, but for Unix/Linux, and specifically for “bash”.  I’ll give you a “bash” answer for your question, based on the answers to that other question:

ls -d *_* | grep '^\(.*\)_\1$' | while read xx
    x=$(echo "$xx" | sed 's/^\(.*\)_\1$/\1/')
    mv "$xx" "$x"

Perhaps you can find a version of “bash” that you can download.  Perhaps somebody who knows PowerShell can adapt the above so you can use it.

share|improve this answer
Thank you for your answer. I'll give it a try. If someone could adapt this for PowerShell, that would be fantastic! – Philip Seyfi Nov 16 '12 at 19:19
If you “have access to Linux”, you should be able to use the above as-is. – Scott Nov 16 '12 at 19:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.