Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

2 Answers 2

up vote 4 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
1  
Ubuntu is debian –  Reuben Swartz Apr 5 '11 at 12:53
    
@die_humans: Look here ubuntuforums.org/showthread.php?p=6642616 for one way to do it. another way would be a shell script. –  Christoph Apr 5 '11 at 13:23

Your Answer

 
discard

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.