My bash script makes copies of some files to some multiple directories.
In order to save space and maximize speed, I would prefer to make hardlinks instead of copies, since all copies need to remain identical during their life anyway.
The script is ran in different computers, though, and there may be the case where the destination directory exists in a different volume to the origin's. In such a case, I cannot make a hardlink and need to just copy the file.
How do I check if origin and destination directory exist in the same volume, so that I either hard link or copy depending on it?
The easy way, by checking whether
ln
fails wherecp
succeeds: