0

See:

mkdir sym
cd sym
mkdir one

//Create the symlink
ln -s one two

ls -l
drwxr-xr-x  2 lola lola 4096 2012-02-14 07:58 one
lrwxrwxrwx  1 lola lola    3 2012-02-14 07:58 two -> one

Now, if I put something in one I could reach it in two. For what I understand two is the name of the symlink, and creates a directory to it (namely, two) [is this correct?].

Question: Is two is a directory that points to one?

But if I do:

(assuming a clean configuration)
mkdir sym
cd sym
mkdir one
mkdir two  <--- notice the creation of two!!

//Create the symlink
ln -s one two

drwxr-xr-x  2 lola lola 4096 2012-02-14 07:59 one
lrwxrwxrwx  1 lola lola    3 2012-02-14 07:59 two
but in two/
lrwxrwxrwx 1 lola lola 3 2012-02-14 07:59 one -> one

If I put something in one I cannot reach it in two.

But from man ln:

SYNOPSIS
   ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)
   ln [OPTION]... TARGET                  (2nd form)
   ln [OPTION]... TARGET... DIRECTORY     (3rd form)
   ln [OPTION]... -t DIRECTORY TARGET...  (4th form)

I'm trying to do the 3rd form, that is: create a symlink from one directory to another directory.

Could you give me a hint about my mistake? I think is conceptual (and technical).

CJ Dennis
  • 4,226
  • 2
  • 40
  • 69

2 Answers2

1

In your first example, "two" is not a directory. It is a simlink (basically a small label that says "if someone asks for me, look in "one" in stead.

In the second case, you indeed use the 3rd form. However what this form does is "Make a simlink to TARGET inside directory DIRECTORY. Because "two" is a directory, the ln command recognizes the second example as the 3rd form.

Claude
  • 8,806
  • 4
  • 41
  • 56
  • I would like to know how to create a symlink from one dir to another dir, in which If I put a file in *one* I would be able to manager it in *two*. Assuming that *one* and *two* are created **before** the symlink –  Feb 14 '12 at 13:05
  • When "two" is a directory, it can't be a symlink as well. So you need to remove directory "two" and then create symlink "two". There is no way to "morph" a directory into a symlink If you want something like "everything that is in one, should be in two as well, but two can also contain other stuff", that is not possible with symlinks. There are some filesystems that can so that, but those are very murky waters... – Claude Feb 14 '12 at 13:25
  • Just to clarify: I don't know of any filesystems where you can make something that is both a directory and a symlink (I don't think it's possible at all); you could mount some filesystem on "two" though that results in both the files in "one" and in "two" showing. – Claude Feb 14 '12 at 13:28
  • Great!, that's the answer I was looking for. I was confused about the melting of directories and symlinks. Thank you (hating my down vote :/) –  Feb 14 '12 at 13:32
0

A symbolic link is a kind of file. It is not a directory. The readlink() system call reads the characters in the symbolic link file. That is where the "-> one" comes from in the ls display.

In order for your example to work ls -l two should show "../one" because the two symlink is inside the one directory, so for it to correctly reference the directory is has to go "up" to find one.

jim mcnamara
  • 16,005
  • 2
  • 34
  • 51