3

What's the difference between --link and --reflink=always?

I use the following command as an mv substitute, and I am wondering if using --reflink is a better choice.

command gcp -r --link --archive --verbose "${opts[@]}" "$@"
# delete the sources manually

1 Answer 1

6

--link causes cp to create hard links instead of copying. Once the “copy” is complete, assuming it’s in the same file system (which is required for hard links), a single instance of the file is present on disk, with two or more directory entries pointing to it. This is the desired external state, i.e. the fact that several directory entries point to the same file is visible — they point to the same inode. Changes made through one of the directory entries will be visible through the other as well.

--reflink=always requests an optimised copy, if possible. This can take various forms; the most famous is copy-on-write, but it can also be implemented as a server-side copy on networked file systems. Once the copy is complete, it may be the case that a single copy of the data blocks exists on disk, but there are two files, and each directory entry points to a different file. Changes made through one directory entry will not be visible through the other; each file leads a separate life (except for side-effects of the shared data blocks, e.g. disk corruption will affect both files).

Put another way, --link explicitly requests the creation of new directory entries pointing to the same file, sharing subsequent changes. --reflink=always requests the creation of new files, with potential optimisations, and isolated subsequent changes.

As an mv alternative, --link is more appropriate than --reflink=always — it will result in less work for the operating system.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .