Cloning Directories in Ruby using Hard Links
Hard links exist under windows 7 so you can clone huge directories or files without taking up any extra disk space. Both the original and the copy are equal and apps can't tell the difference between them - because we are using true hard links (not shortcuts or symbolic links).
The dos command for cloning a file is simply
mklink /H original clone
If you delete the original file, the clone is still there and indistinguishable from the original file. You can clone as many times as you like and no extra disk space is used.
I'm not aware of a way of recursively hard linking directories (files as hard links, sub directories as real directories) in windows or linux using the standard commands, so here is a recursive directory cloning utility written in Ruby. It uses the FileUtils.ln method to do the file cloning. This works under both windows 7 and linux.
You can invoke it using:
ruby ln_r.rb [options] dir1 dir2 ...
-v, --verbose Output more information
-t, --test Run test copy on test data dirs - Andy only
-r, --report Display directory of source and target dirs after finish
-c, --countsize Display bytes saved by using hard linking
-d, --dontdeletetarget Dont rm -r * target directory first
-h, --help Display this screen
Its true that you can achieve the above in linux with
cp -lr from to
where -r means recursive copy and -l mean use linking.
Under windows, the COPY isn't so smart and so the above ruby script may be of help. Alternatively you can use a port of the linux cp command under windows - and it seems to work OK. See Port of the most important GNU utilities to Windows