How do I delete the target of a symbolic link without deleting the link itself?

I have a symbolic link ~/Desktop/test.txt which points to ~/rendu/test.txt.

I know ONLY the path of ~/Desktop/test.txt, I want a fast way to delete ~/rendu/test.txt WITHOUT deleting the symbolic link.

For the one who want to know why: I have a file named crypted.xxx on my desktop, which is encrypted and contains my password.

When I want to update my encrypted file, I decrypt it and it create crypted.txt in a special directory. So I make a link to that file on my desktop for practical reasons. But after looking at my crypted.txt, I want to quickly delete this crypted.txt (but not the link in the desktop).


Solution 1:

using find to find the symlink and then using readlink to get the full path to the target to rm:

find ~/Desktop/ -type l -name 'test.txt' -exec bash -c 'rm "$(readlink -f "$1")"' _ {} \;

Or as you know the link name already:

rm "$(readlink -f ~/Desktop/test.txt)"

Solution 2:

Simply use:

printf "" > "$(readlink '/path/to/link')"

to clear the file, or

rm "$(readlink '/path/to/link')"

to remove the file.