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 have a tree of folders. Some of them contain file named ".file.php" How do i rename all the files with this name recursively in the tree to ".file1.php"? I'm on debian server.

share|improve this question
up vote 5 down vote accepted

The full solution would look as follows

find -name '*.file.php' -exec rename 's/\.file\.php$/.file1.php/' {} \;
share|improve this answer

do you have rename on debian? idk, but since it's available on ubuntu, I guess so.

NAME rename - renames multiple files

SYNOPSIS rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

DESCRIPTION "rename" renames the filenames supplied according to the rule specified as the first argument. The perlexpr argument is a Perl expression which is expected to modify the $_ string in Perl for at least some of the filenames specified. If a given filename is not modified by the expression, it will not be renamed. If no filenames are given on the command line, filenames will be read via standard input.

   For example, to rename all files matching "*.bak" to strip the
   extension, you might say

           rename 's/\.bak$//' *.bak

   To translate uppercase names to lower, you'd use

           rename 'y/A-Z/a-z/' *

an example copied from a google result might be already quite near to what you want:

Here is an example of the rename command:

rename -n ’s/.htm$/.html/’ *.htm

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 .htm to .html.

If the output of the above test run looked ok then you could run the final version:

rename -v ’s/.htm$/.html/’ *.htm

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....

share|improve this answer
how do i do it recursively in a tree of folders? – die_humans Apr 5 '11 at 12:21
Ubuntu is debian – Reuben Swartz Apr 5 '11 at 12:53
@die_humans: Look here for one way to do it. another way would be a shell script. – Christoph Apr 5 '11 at 13:23

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.