[buug] additional hard links on directories

Michael Paoli Michael.Paoli at cal.berkeley.edu
Sat Oct 25 22:56:41 PDT 2008


Unix(/Linux/...) - additional hard links on directories

... came up in discussion at BUUG some meetings back, ... been meaning to
post this, ... anyway ...

Additional hard links on directories are generally a bad idea (they
tend to be rather to quite problematic).  Nevertheless, generally
speaking, Unix permits such - but restricts their use (creation) to
that of superuser - probably owing to the hazards and chaos they can cause.
Linux seems to be even more restrictive in this regard (probably by design).

Anyway, keeping the preceeding hazards/caveats/warnings in mind ...

For an example on Solaris (and a bit more discussion), see:
news:d85eb83f.0407172105.112f6714 at posting.google.com
(which one can also view via:
http://groups.google.com/group/comp.unix.solaris/msg/f49910ca0cafe77f?dmode=source
)

And, for an example in Unix 7th Edition (under emulator):
$ unix-v7

PDP-11 simulator V3.3-2
Disabling XQ
@boot
New Boot, known devices are hp ht rk rl rp tm vt
: rl(0,0)rl2unix
mem = 177856
# mkdir /tmp
# cd /tmp
# mkdir dir
# cd dir
# ls -lid . /tmp/dir
  1951 drwxrwxrwx 2 root       32 Sep 22 05:47 .
  1951 drwxrwxrwx 2 root       32 Sep 22 05:47 /tmp/dir
# ln . dir
ln: . is a directory
# ln -f . dir
# ls -lid /tmp/dir . dir
  1951 drwxrwxrwx 3 root       48 Sep 22 05:48 .
  1951 drwxrwxrwx 3 root       48 Sep 22 05:48 /tmp/dir
  1951 drwxrwxrwx 3 root       48 Sep 22 05:48 dir
# pwd
/tmp/dir
# rm -rf dir
rm:  
dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir:  
cannot read
# ls
dir
# cd dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir
# cd dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir
# cd dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir
# cd dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir
# pwd
/tmp/dir
# ls -lid /tmp  
dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/..
  1952 drwxrwxrwx 3 root       48 Sep 22 05:47 /tmp
  1952 drwxrwxrwx 3 root       48 Sep 22 05:47  
dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/..
# unlink dir
unlink: not found
# /etc/unlink dir
/etc/unlink: not found
# ls -ld /sbin /usr/sbin
/sbin not found
/usr/sbin not found
# ls -ld /bin /usr/bin
/usr/bin not found
drwxrwxr-x 2 bin      2512 Sep 22 05:32 /bin
# /bin/unlink dir
/bin/unlink: not found
# echo $PATH

# ed unlink.c
?unlink.c
0a
main(){
unlink("dir");
}
.
w
25
q
# cc unlink.c
# ls -lid /tmp/dir . dir
  1951 drwxrwxrwx 3 root      112 Sep 22 05:51 .
  1951 drwxrwxrwx 3 root      112 Sep 22 05:51 /tmp/dir
  1951 drwxrwxrwx 3 root      112 Sep 22 05:51 dir
# ls
a.out
dir
unlink.c
# ./a.out
# ls
a.out
unlink.c
# ls -lid /tmp/dir .
  1951 drwxrwxrwx 2 root      112 Sep 22 05:51 .
  1951 drwxrwxrwx 2 root      112 Sep 22 05:51 /tmp/dir
#





More information about the buug mailing list