Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to edit a symlink with a text editor?

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.

like image 271
4ae1e1 Avatar asked Mar 27 '14 03:03

4ae1e1


People also ask

Can you edit symlinks?

No. The symlink system call will return EEXIST if newpath already exists. You can only link from a new node in the filesystem.

Can you chain symlinks?

Yes. You can only stack so much symbolic links together before the kernel and/or application refuse to follow the chain.

How do I change a symbolic link in Windows?

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.


1 Answers

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

wdired editing a symlink

(BTW: I'm using Smex to give Emacs M-x command search & execute a more ergonomic UI + fuzzy matching)

like image 71
ocodo Avatar answered Oct 29 '22 03:10

ocodo