Wednesday, 12 December 2007

symbolic links

Something that people might run into this and get confused, or worse, panic at the posibility of losing data.

I was trying to explain the issue but it'll be easier to just write the syntax out and explain it there.

ls -l
total 0
drwxr-xr-x 2 user1 group1 68 Dec 12 11:47 dir1

ln -s dir1 dir2


Here you create the symlink from one directory and no problem here.

ls -l
total 8
drwxr-xr-x 2 user1 group1 68 Dec 12 11:47 dir1
lrwxr-xr-x 1 user1 group1 4 Dec 12 11:48 dir2 -> dir1


Next:

ls -l
total 0

drwxr-xr-x 2 user1 group1 68 Dec 12 11:47 dir1
drwxr-xr-x 2 user1 group1 68 Dec 12 11:49 dir2


ln -s dir1 dir2


Oops! Does this replace dir2?

ls -l
total 0
drwxr-xr-x 2 user1 group1 68 Dec 12 11:47 dir1
drwxr-xr-x 3 user1 group1 102 Dec 12 11:50 dir2

ls -l dir2/
total 8
lrwxr-xr-x 1 user1 group1 4 Dec 12 11:50 dir1 -> dir1

Nope! It just creates a symbolic link inside the 2nd directory!

So don't worry! Remember to delete the symbolic link just use rm

-P
Post a Comment