When I have a symlink for a folder and then try it again with -sf
option I end up having another symlink inside the original source folder symlinking to itself. Why is this happening and how do I make sure duplicate symlinks are not created ?
➜ foo pwd
/home/ubuntu/foo
➜ foo ln -sf ~/foo/bar ~/foo/baz
➜ foo tree
.
├── bar
│ └── test.sh
└── baz -> /home/ubuntu/foo/bar
2 directories, 1 file
➜ foo ln -sf ~/foo/bar ~/foo/baz
➜ foo tree
.
├── bar
│ ├── bar -> /home/ubuntu/foo/bar
│ └── test.sh
└── baz -> /home/ubuntu/foo/bar
3 directories, 1 file
Distro : Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-106-generic x86_64
shell : zsh with Oh my zsh plugin
ln -sf ~/foo/bar ~/foo/baz
second timeln -sf ~/foo/bar ~/foo/bar
which created the second link.-n
option. Please refer to my answer below