Server Fault is a question and answer site for system and network administrators. 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 lot of identically named "data.xml" files on my system in different directories.

A basic Windows search easily finds all of these. I would love to be able to do a search on these, find them, and copy them to a directory so there are named data_1.xml etc. etc.

Just the fact that they're all in one directory is what I'm aiming for.

I've tried using Teracopy to do the heavy lifting of copying but it's not renaming the files correctly. Is there any tool out there for something like this?

share|improve this question
up vote 1 down vote accepted

Just for completeness, here's a Windows-based solution to run in the CMD shell:

@echo off

set SRC=c:\source
set DST=c:\dest
set FN=0

for /F "usebackq delims=" %%i in (`dir /s /b %SRC%\*.xml`) do call :docopy "%%i"
goto end

set /A FN=%FN% + 1
echo copy %1 "%DST%\%~n1_%FN%%~x1"
share|improve this answer
Due to some error on my part or the solution's response, I booted up Windows and gave this a go. While I had to add an actual copy line instead of just the echo line, it worked great! :D – bobber205 Mar 11 '11 at 19:26


find / -name "*.xml" -exec cp  {} ./ \;

Should do the job.

Store this script say and then ./

this would rename them

for j in `ls *.xml`
  echo $orig
  mv $orig orig$i.xml
   i=`expr $i + 1`


another way to copy is

 find / -name "*.xml" | xargs cp {} /path/to/copy
share|improve this answer
Good answer but while it wasn't overly clear in the original question the OP is using Windows. – John Gardeniers Mar 10 '11 at 21:23
I actually have access to both OS X and Windows for this! :D – bobber205 Mar 10 '11 at 21:43
Thanks so much for your solution! A++++++++ – bobber205 Mar 10 '11 at 21:43
Just now got some time to try this out and the find command replaces the info.xml file with the next one it copies so I only end up with one. :( – bobber205 Mar 11 '11 at 18:38
@bobber205 try this find / -name "*.xml" | xargs cp {} /path/to/copy – Registered User Mar 12 '11 at 20:33

The previously suggested solution failed im my case when the target directory contained files and directories with whitespaces and non-latin characters in their names. It turns out Windows (Vista & and above) comes with a command line tool for robust copy, called Robocopy. The usage is very simple:

robocopy c:\soruce\from f:\target\to

Worked very well. (My thanks go to Chris Hoffman from for his post that gave me this idea)

share|improve this answer
or just find / -name "*.xml" -print0 | xargs -0 cp -t /path/to/copy – rudimeier Dec 29 '13 at 12:12

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.