Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>On the difference between cp and tar to copy the directory hierarchies, a simple experiment can be conducted to show the difference:</p> <pre><code>alastair box:~/hack/cptest [1134]% mkdir src alastair box:~/hack/cptest [1135]% cd src alastair box:~/hack/cptest/src [1136]% touch foo alastair box:~/hack/cptest/src [1137]% ln -s foo foo-s alastair box:~/hack/cptest/src [1138]% ln foo foo-h alastair box:~/hack/cptest/src [1139]% ls -a total 0 -rw-r--r-- 2 alastair alastair 0 Nov 25 14:59 foo -rw-r--r-- 2 alastair alastair 0 Nov 25 14:59 foo-h lrwxrwxrwx 1 alastair alastair 3 Nov 25 14:59 foo-s -&gt; foo alastair box:~/hack/cptest/src [1142]% mkdir ../cpdest alastair box:~/hack/cptest/src [1143]% cp -rfp * ../cpdest alastair box:~/hack/cptest/src [1144]% mkdir ../tardest alastair box:~/hack/cptest/src [1145]% tar cf - * | (cd ../tardest ; tar xf - ) alastair box:~/hack/cptest/src [1146]% cd .. alastair box:~/hack/cptest [1147]% ls -l cpdest total 0 -rw-r--r-- 1 alastair alastair 0 Nov 25 14:59 foo -rw-r--r-- 1 alastair alastair 0 Nov 25 14:59 foo-h lrwxrwxrwx 1 alastair alastair 3 Nov 25 15:00 foo-s -&gt; foo alastair box:~/hack/cptest [1148]% ls -l tardest total 0 -rw-r--r-- 2 alastair alastair 0 Nov 25 14:59 foo -rw-r--r-- 2 alastair alastair 0 Nov 25 14:59 foo-h lrwxrwxrwx 1 alastair alastair 3 Nov 25 15:00 foo-s -&gt; foo </code></pre> <p>The difference is in the hard-linked files. Notice how the hard-linked files are copied individually with <code>cp</code> and together with <code>tar</code>. To make the difference more obvious, have a look at the inodes for each:</p> <pre><code>alastair box:~/hack/cptest [1149]% ls -i cpdest 24690722 foo 24690723 foo-h 24690724 foo-s alastair box:~/hack/cptest [1150]% ls -i tardest 24690801 foo 24690801 foo-h 24690802 foo-s </code></pre> <p>There are probably other reasons to prefer tar, but this is one big one, at least if you have extensively hard-linked files.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload