Wednesday, January 2, 2008

Old Dog Learns New Trick

Here's something I should have known years ago.

Use hard links instead of cp to make fast "copies" of files.

I have files saved in directory archive/ that I copy to a work/ directory, then process them, then delete them from work/ but keep indefinitely in archive/.

These are large files so cp takes a while. What I should have been doing all along is using ln to create links in work/ to the files in archive/. This is much faster since there is no real copying. It works out OK because the processing is a read-only operation on the files so nothing is changed in archive/.

(This is all scripted in a Ruby script, of course.)

No comments: