Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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 am trying to bulk change some files in bash that have spaces and unwanted endings to their extension.

For example from




I will show whole progress in case I made something harder than it should actually be. So at first I started with something like

for file in `find /Users/phwd/Desktop/Film\ Sheet\ Music\ Scores\ 2  *.\!ut.\!ut`;
 mv $file `echo $file | sed 's/\(.*\)\.\!\ut\.\!\ut/\1/'`;

The above did not work for spaces when sending for mv so I changed to this

find /Users/phwd/Desktop/Film\ Sheet\ Music\ Scores\ 2  *.\!ut.\!ut | while read file
    mv $file `echo $file | sed 's/\(.*\)\.\!\ut\.\!\ut/\1/'`;

This worked almost but mv started saying an arbitrary message

usage: mv [-f | -i | -n] [-v] source target
       mv [-f | -i | -n] [-v] source ... directory

I am over thinking something ?

share|improve this question
Execute the script with sh -xv sciptfile, it will show you the commands being executed. – João Pinto Dec 25 '10 at 18:01
up vote 2 down vote accepted

So if you just want to remove the ending !ut.!ut I would suggest something like this:

for file in `find ...`; do
  mv "$file" "${file%.\!ut.\!ut}"

In this case the shell does its job and removes the ending. This feature is called parameter expansion.

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.