When we create a symlink, the number of bytes the symlink takes up is exactly the length of the origin it points to. For instance,
$ ln -s dest link1
$ ln -s longer_dest link2
$ ls -l
lrwxrwxrwx 1 username 4 Mar 26 20:21 link1 -> dest
lrwxrwxrwx 1 username 11 Mar 26 20:21 link2 -> longer_dest
where link1
takes up 4 bytes, which is the length of dest
; link2
takes up 11 bytes, which is the length of longer_dest
. Therefore, symlinks are in fact no more than the destination path stored in plain text. So I am wondering if it is possible to edit (the destination) of a symlink in text editors, preferably Emacs. I googled for a while and couldn't find anyone talking about this. Note that this question is purely out of curiosity; I know full well that I can overwrite a symlink by ln -f -s
.
No. The symlink system call will return EEXIST if newpath already exists. You can only link from a new node in the filesystem.
Yes. You can only stack so much symbolic links together before the kernel and/or application refuse to follow the chain.
With Windows Link Shell Extension installed, you can right-click on the link in Windows Explorer and check the properties. There is a tab that allows you to change the link directly.
Yes, in Emacs this is possible in dired-mode, specifically wdired (writable dired) mode.
Note, dired and wdired both are built-in packages.
Here's an example...
(BTW: I'm using Smex to give Emacs M-x
command search & execute a more ergonomic UI + fuzzy matching)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With