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).

3

2 Answers

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)" 
4

Simply use:

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

to clear the file, or

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

to remove the file.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy