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
  • 55,668
  • 25
  • 164
  • 183
  • 1
    https://askubuntu.com/questions/108771/what-is-the-difference-between-a-hard-link-and-a-symbolic-link has all you need to know about this. Short version: drop the -s so you use a hardlink ( @ravexina ) – Rinzwind Apr 06 '20 at 08:32

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
  • 55,668
  • 25
  • 164
  • 183
  • I'm not sure if OP not rather wants hard links , cp -rl ... ? – pLumo Apr 06 '20 at 08: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 06 '20 at 08: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. – misskecupbung Apr 06 '20 at 08:47