move files/directories with similar names, matching rule

0

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.

Keith Loughnane

Posted 2012-10-24T12:02:48.173

Reputation: 123

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 – 2012-10-24T12:15:22.790

You want to merge (while moving) folders with similar names? Do they all have ' swapped for _? – dset0x – 2012-10-24T12:16:32.623

Answers

0

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"

ex:

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

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 ./myScript.sh fileName

A simple script like:

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

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.

gabriel_agm

Posted 2012-10-24T12:02:48.173

Reputation: 313

I'm really sorry, I don't have the rep on this site to vote you up, you're a life saver. – Keith Loughnane – 2012-10-26T08:50:46.847