1

I started to study the Solaris in my university. Teacher told me to do a hardlink to a directory. And he said that I can not to use mount command. For example: # mount -F lofs /dir1/dir2 /dir1/hardlink2
I know that Unix doesn't allowed hardlink to a directory. I was looking for other ways but I found nothing. And I don't know how I can do this hardlink.

Do you know way how create a hardlink to a directory in Solaris?

Anthon
  • 78,313
  • 42
  • 165
  • 222
Nikolay Bildeyko
  • 129
  • 1
  • 1
  • 7
  • In most *nix operating systems, you have to be running as root (a.k.a. superuser) to create a hardlink to a directory. The operation is restricted because it can make a mess of a file system. See [Linux: How does hard-linking to a directory work?](http://unix.stackexchange.com/q/108843/80216) – G-Man Says 'Reinstate Monica' Oct 11 '14 at 17:55
  • @G-Man I'm running as root, but than I use ln command, it displays an error: .... is a directory. I read manual about ln. This command in Solaris has only 3 settings: -f-n (about messages), -s (symbolic link). So I can't use ln in this case. – Nikolay Bildeyko Oct 11 '14 at 18:15
  • 3
    Oh, yes, belt and suspenders. The _operating system_ doesn't allow a process to create a hardlink to a directory unless it's running as root -- but *also* the `ln` program doesn't allow a *user* (*any* user) to do it. (1) Check the man page for `ln` on your system. There may be an option (like `-d` or `-F`) to tell `ln` to override the restriction. (2) Check to see whether you have a `link` command. (3) If those don't work, try writing a one-line C program to call the `link` system call. – G-Man Says 'Reinstate Monica' Oct 11 '14 at 18:22
  • 1
    @G-Man `link` command works. Thank you very much. – Nikolay Bildeyko Oct 11 '14 at 18:30

1 Answers1

1

Looks like G-Man already gave you an answer, but another option, slightly sneaky if you have the automounter installed, you could use an automount. Depending on the needs, this may be a little bit cleaner since linking a directory can cause confusion.

sleepyweasel
  • 1,013
  • 5
  • 11