1

To create symlinks I use:

ln -s /folder /target

But when I delete a file from /target it also get removed from /folder. However I want to keep the file in /folder even though I remove it from /target. How can I do that?

Ravexina
  • 57,256

1 Answers1

2

That's the default and correct behavior.

As you know, /target is just a symbolic link to /folder. When you go inside /target, the files you see are actually living inside /folder. These are actual files and not symbolic links. So when you delete them, you are deleting the actual files living in /folder.

In other words, creating a symlink to a directory does not creates a link for each file/directory inside that directory.


What to do?

Now we know that we have to create a symbolic link for each and every file in "folder". To do that use cp:

cp -rs /folder /target

or as mentioned in the comments to get hard links:

cp -rl /folder /target

You can also use lnddir.

Ravexina
  • 57,256