I saw the following interesting usage of tar in a co-worker’s Bash scripts:
`tar cf - * | (cd <dest> ; tar xf - )`
Apparently it works much like rsync -av does, but faster. The question arises, how?
-m
EDIT: Can anyone explain why should this solution be preferable over the following?
cp -rfp * dest
Is the former faster?
On the difference between cp and tar to copy the directory hierarchies, a simple experiment can be conducted to show the difference:
The difference is in the hard-linked files. Notice how the hard-linked files are copied individually with
cpand together withtar. To make the difference more obvious, have a look at the inodes for each:There are probably other reasons to prefer tar, but this is one big one, at least if you have extensively hard-linked files.