Super User is a question and answer site for computer enthusiasts and power users. 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

We were moving about 4TB of files to a Windows Server2 008R2 from a OS X Server. A lot of the filenames couldn't be moved because of incompatible characters. We ran a renaming tool to fix the problem and copied again. My problem is now I have a lot of folders that have very similar names like "O'Neil" and "O_Neil". In fact as far as I can tell they all conform to this rule. There are too many to do by hand, I'm thinking of writing a script but I have limited experience with scripting. I'd like to compare the modify date or the filesize and merge or move the folders to an archive and leave one set in place. I'm not sure about best practice in this situation.

  1. In theory what is the best practice, merge by date, archive the smaller versions?
  2. In practice how can I go about fixing this are there tools? Script ideas?

Any help is hugely appreciated.

share|improve this question
I think the simplest solution would be to go throught he files give the file meaningful names. A tool won't be able to do that. – Ramhound Oct 24 '12 at 12:15
You want to merge (while moving) folders with similar names? Do they all have ' swapped for _? – zmode Oct 24 '12 at 12:16
up vote 0 down vote accepted

This is not a straight question - its a request for comments and sample scripts - and may generate a lot of discussions. Its better to post many small focused questions to get an answare.

Anyway, in the mac server you can count on a miriad of command-line tools to help you out on scripting.

First, you can list all the files/folders you want to apply rules on with find:

$> find "rootPathToSearchOn" -name "namingRule" -regex "betterNamingRule"


$> find . -maxdepth 1 -regex "./[a-zA-Z]*[_'][a-zA-Z]*"

This way you can separate those with underlines from those with quotes. Then passing the output of find to 'xargs' you can call a script for the selected files:

$> find . -maxdepth 1 -regex "./[a-zA-Z]*[_][a-zA-Z]*" -print0 | xargs -0 -I fileName ./ fileName

A simple script like:

nameToTest=`echo $1 | tr "_" "'"`
if [ -e $nameToTest ];
then echo $nameToTest has a collision to $1;

Should output something like:

./o'neil has a collision to ./o_neil

In that case, you can fill the 'then' block with desired actions.

Now, the strategy to merging depends on your scenario - the creation date of the directory does not indicate the date of its contents - and summing the file size of the directory contents does not indicate the activity on it.

share|improve this answer
Thanks, so much. – Keith Loughnane Oct 24 '12 at 14:38
I'm really sorry, I don't have the rep on this site to vote you up, you're a life saver. – Keith Loughnane Oct 26 '12 at 8:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .