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

In a folder I have a .run file and am trying to change the extension to .clu. The problem is that I have tried

rename 's/.run$/.clu/' *.run

But this does absolutely nothing to the file.

Note: I'm not trying to convert the file, just to rename the extension.

share|improve this question
Do you have write permission on the file? – Jos Jun 27 '14 at 10:54
I do have write permission. – Dobz Jun 27 '14 at 12:16
Please, show the name of the files you are trying to rename. ls or whatever is useful. – Braiam Jun 27 '14 at 13:51
for file in *.run ; do mv -f $file `echo $file | sed 's/\(.*\.\)run/\1clu/'` ; done this works. – Dobz Jun 27 '14 at 14:37

I don't know what your problem is. What you've posted works:

$ mkdir test
$ touch test/test{01..10}.run
$ rename 's/\.run$/.clu/' test/*.run -vn
test/ renamed as test/test01.clu
test/ renamed as test/test02.clu
test/ renamed as test/test03.clu
test/ renamed as test/test04.clu
test/ renamed as test/test05.clu
test/ renamed as test/test06.clu
test/ renamed as test/test07.clu
test/ renamed as test/test08.clu
test/ renamed as test/test09.clu
test/ renamed as test/test10.clu

The -vn is just telling us what it would do if run without it.

I'm escaping the dot (otherwise it's a REGEX "anything") but it really makes no difference here. It works as well without it.

Is it possible that you're actually running rename.ul? Check to make sure you're using the Perl rename (which takes the syntax we're using) with dpkg -S $(readlink -f $(which rename))

  • perl: /usr/bin/prename is good.
  • util-linux: /usr/bin/rename.ul is bad. For some reason you're using a very limited version of rename. Something very squiffy has happened.

For the moment, see if prename exists (you could just use that for now) and if not, start asking why Perl isn't installed properly. It would suggest you don't have Ubuntu installed.

Or if you're happy using rename.ul, the following should work:

rename.ul .run .clu *.run

But that might munch a file like into test.clu.hooray.clu which obviously isn't great.

share|improve this answer
looking at your code, it could be the fact that after the 's' you have '/\' while I only have '/', this may be my problem. I'll try it out. – Dobz Jun 27 '14 at 12:15
@RussellHickey As I commented on another, now deleted answer, it makes absolutely no difference here. As you had it, . means "any character", while \. means . - they both work here. – Oli Jun 27 '14 at 12:34

You just use mv:

mv oldname newname

mv is used to move/ rename files. Refer to the man page of mv for more.

share|improve this answer
This will be used in a build file so the names will not be known. – Dobz Jun 27 '14 at 10:51
You could do mv *.run *.clu if you are sure that you want to rename all *.run files to *.clu in the directory you are executing this command. – i08in Jun 27 '14 at 10:54
this will give the output name as '*.clu' I was trying to just change extention. – Dobz Jun 27 '14 at 10:57
for file in *.run ; do mv $file echo $file | sed 's/\(.*\.\)run/\1clu/' ; done this has seemed to worked – Dobz Jun 27 '14 at 10:57
@Jobin mv *.run *.clu will either fail or move all *run files and all but one *clu file into a directory ending with clu if one happens to exist and in the right alphabetical order. In any case, it will most certainly will not simply change the extensions. – terdon Jun 27 '14 at 11:30

My prefered in cases like this is mmv (it is not installed by default in Ubuntu, but you can install it using sudo apt-get install mmv command):

mmv -n '*.run' '#1.clu'

The -n means that it's a test run and will not actually change any files. It will show you a list of files that would be renamed if you removed the -n. In the case above, it will convert all files in the current directory from a file extension of .run to .clu.

mmv -v '*.run' '#1.clu'

The -v is optional, but it's a good idea to include it because it is the only record you will have of changes that were made by the rename command.

See man mmv for more info.

share|improve this answer
That's good to know thanks. – Dobz Jun 27 '14 at 12:13

You don't need to use rename for this. You can do it using basename:

for f in *run; do mv "$f" "$(basename "$f" .run)".clu; done

basename will print a file's name (no path) and also removes an optional suffix. Therefore, "$(basename "$f" .run)".clu is the name of the file $f with the .run extension replaces with clu.

You can also just use bash's own string manipulation features:

for f in *run; do echo mv "$f" "${}".clu; done

The construct ${var%%string} removes the string string from the end of the variable $var.

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.