The results of both has to be the same, in that a hard link is created to the original file.
The difference is in the intended usage and therefore the options available to each command. For example, cp
can use recursion whereas ln
cannot:
cp -lr <src> <target>
will create hard links in <target>
to all files in <src>
. (it creates new directories; not links) The result will be that the directory tree structure under <target>
will look identical to the one under <src>
. It will differ from cp -r <src> <target>
in that using the latter will copy each file and folder and give each a new inode
whereas the former just uses hard links on files and therefore simply increases their Links
count.
When used to copy a single file, as in your example, then the results will be the identical.
cp: illegal option -- l
are you sure that cp has an l option? – Tom Aug 22 '18 at 17:01