removing symbolic link target
I'm sorry if this is a duplicate, but most of the posts I could find on this subject pertains to removing a symbolic link.
I have 2 symbolic links current -> /home 1.3 previous -> /oldhome 1.2 I have a bash script that copies the current to the previous. Before I do that though I want to remove the previous. I don't want to just remove the link. I also want to remove the target of the link. The problem is that I don't know where the previous link is pointing to because it's a versioned directory and I won't know what the version is within the script. If deleting the links target isn't possible, I can solve this problem if anyone can tell me how to print out what the link is pointing to. ****update**** I've just discovered readlink which returns the directory it's pointing to. With that I can solve my issue, but I'd still like to know if deleting a symbolic link's target through the link is possible. For example (I know this doesn't work) echo previous returns: /oldhome 1.2 Thank you for any help. |
How about inserting some diagnostics in the script to tell you exactly what it's doing?
|
Quote:
|
Hi,
For the benefit of anyone else visiting this thread, the final answer is: rm -r "`readlink -f your_link`" The "-f" means this will work even through more than one layer of symlinks, removing the final file or directory. The funny quoting armours the backticks against spaces in file or directory names. I don't believe there is a one-shot command to do this. Certainly GNU rm has no "--dereference" option. TIM |
Quote:
Thanks for that. Luckily that wasn't something I needed or I may have been searching for that for a while as well. Marking this as complete now. |
All times are GMT -5. The time now is 12:12 AM. |