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?

1

1 Answer 1

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.

3
  • I'm not sure if OP not rather wants hard links , cp -rl ... ?
    – pLumo
    Apr 6, 2020 at 8:36
  • I'm not sure about that, the question was not so clear (take a look at edit history), it mentioned symlinks so I went with that.
    – Ravexina
    Apr 6, 2020 at 8:37
  • Thank you for editing, sir. Yes, I mean like that. But I want to use a symlink, not cp because the directory is updated every day. Apr 6, 2020 at 8:47

You must log in to answer this question.

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