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 want to rename files as to delete unneccessary dots. ie:

File.something.jpg -> Filesomething.jpg
I.Have.Too.Many.Dots.png -> IHaveTooManyDots.png

How can this be done? find -name *.*.* lists them all, but I've been unable to write an expression for sed as it doesn't support lazy regexes.

share|improve this question
up vote 2 down vote accepted

Give this a try:

sed ':a;s/\.\([^.]\+\)\./\1./;ta' 

You could use it like this:

find -name "*.*.*" | xargs -I % bash -c 'mv "%" "$(echo "%" | sed "s|^./||;:a;s/\.\([^.]\+\)\./\1./;ta")"'

It's been sprinkled liberally with quotes so it should work with filenames that include spaces.

share|improve this answer
Worked, put all files in my current dir though >:(. Thanks anyways – Robus Sep 14 '10 at 19:30
@Robus: Did you use the version with basename? That was a mistake. Sorry about that. The revised version shouldn't move files from subdirectories to the current directory. – Dennis Williamson Sep 14 '10 at 19:33

Using bash:

find . -name '*.*.*' -exec bash -c 'base=${0##*/}; base=${base%.*}; mv "$0" "${0%/*}/${base//./}.${0##*.}"' {} \;

Using zsh:

autoload zmv
zmv '(**/)(*).(*)' '$1${2//./}.$3'
share|improve this answer

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.