I recently used a little trick to manipulate symlinks from within emacs using dired and iedit, which may come in handy in some situations, so I thought I'd share it here.
I had a directory containing all sorts of binaries, and another directory which was in the $PATH, and which had symlinks to many of those binaries. Let's say it looks like this:
lrwxr-xr-x 1 root root 71 Jul 16 23:49 executable_1 -> /some/bin/directory/executable_1 lrwxr-xr-x 1 root root 71 Jul 16 23:49 executable_2 -> /some/bin/directory/executable_2 lrwxr-xr-x 1 root root 71 Jul 16 23:49 executable_3 -> /some/bin/directory/executable_3
Now let's say you want to rename
/my/other/directory, but maintain the above symlinks (I mentioned only three here, but in my case there were a few dozens of them).
Luckily emacs is awesome, so it lets you do that in a neat way.
- First, open the symlink directory in emacs (in dired mode - by pressing
C-dwhile in the minibuffer)
- Enter read/write mode, enabling you to edit the directory contents (
- Select the portion of the path that is about to change in the first file (i.e. marking the string "/some/bin", since we want to change it to "/my/other")
- With the string selected, enter
iedit-mode. I bound it to
C-x i, but you might have a different binding. If you don't have
iedit-mode, I strongly suggest that you get it here.
- Delete the selected string, and replace it with "/my/other". All occurrences of "/some/bin/" should change as you type.
- Save the changes to the directory (
- Et Voilla! you're done!
You can apply this trick on many batch modifications in dired that can be based on substring manipulations, this is only one example. You can also use Magnar Sveen's awesome multiple-cursors.el for the concurrent editing of the replaced paths.