0

I ran this command

ln -s /folder1/dir /folder2/soft_link

which did create a soft-link file where /folder2/soft_link pointed to /folder1/dir.

But I notice when I run that same command again, it then creates the file /folder1/dir/soft_link which points to /folder1/dir.

It is only when I run it a third time that it finally says that the soft-link already exists.

But if I run ln -s /folder1/dir /folder2/

it will not create that unnecessary soft link of /folder1/dir/soft_link if I run it a second time.

Which brings me to my question. How come it creates that unnecessary directory if I don't use the -n flag?

1 Answer 1

1

NAME

ln - make links between files

SYNOPSIS

  ln [OPTION]... [-T] TARGET LINK_NAME  
  ln [OPTION]... TARGET  
  ln [OPTION]... TARGET... DIRECTORY  
  ln [OPTION]... -t DIRECTORY TARGET...

ln can be called in different ways. Thus it behaves differently if the last argument is a directory. So you need -n or -T to enforce a specific behaviour.

8
  • "Thus it behaves differently if the last argument is a directory. " But the last argument isn't a directory, it is a soft link.
    – modernNeo
    Commented May 21, 2020 at 2:12
  • Doesn't matter. Directory symlinks are treated like directories in most cases. Commented May 21, 2020 at 2:25
  • @modernNeo you mentioned the -n option, did you see its description?
    – muru
    Commented May 21, 2020 at 2:40
  • @HaukeLaging -n is a dummy option that is always ignored and -T is an unsupported option so you do not seem to talk about the UNIX command ln.
    – schily
    Commented May 21, 2020 at 6:47
  • 1
    @schily In a certain way I never talk about UNIX commands here. But something in the question tells me that I am talking about the same command as the questioner. Commented May 21, 2020 at 16:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .