How to make original file not delete when using symbolic link linux

Viewed 2265

I want to ask when I delete file in folder symlink target, is it possible make the file is still available in original file? I use ls -n /folder /target but when I delete file in /target , in original folder deleted too.

2 Answers

Remove Symbolic Links with rm

rm symlink_name

Remove Symbolic Links with unlink

unlink symlink_name

Unlink command and rm command without -R option doesn't delete regular directory. The two commands delete symbolic link from directory because it's considered as a file so, when using the rm or unlink command to remove a symbolic link from a directory, make sure you don’t end the target with a / character because that will create an error

Please read more in documentation, man pages etc.

As I understood question - you should remove symlink to directory, but make symlink for each file in directory to target directory. So you will have two normal directories and lot of symlink for files.

Only this way you can delete one particular file in target directory and still have it in original directory

If you want to make it work both ways - to delete file in original directory and still have it in target - make non symlink but hard link with ln for each file.

Related