Skip to content
Advertisement

Symbolic link difference between cp -sr and ln -s [closed]

I’m trying to make symbolic links in my Dropbox so that I don’t have duplicate files all over my computer (file space is limited). I’ve come across some confusing behavior in ln -s vs. cp -s. Basically, ln -s seems to make a link to the original folder, but then copies all the files within the folder to a new location. cp -sr recursively makes links to all files within the folder (which is the desired behavior).

For example:

JavaScript

Note the difference in file sizes between the two methods, and the lack of a link for the files made by ln -s. If I go into my file browser and right click to look at the properties, I also see something different.

ln -s

JavaScript

cp -sr

JavaScript

So cp -sr seems to be actually linking each file in a directory, whereas ln -s seems to link the top folder only and copying the files within the folder, thus duplicating files.

Is that correct?

The problem is that if I use cp -sr, only the files themselves are linked, not the top folder. So if I add or delete a file on my harddrive, the change isn’t then copied to Dropbox

Running Linux Mint 18.3

Advertisement

Answer

You’re correct. Here’s info cp explicitly saying that it only links non-directories:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement