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?
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.
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
.
cp
because the directory is updated every day.
Apr 6, 2020 at 8:47
-s
so you use a hardlink ( @ravexina )