I'm refreshing my understanding of a few basic GNU/Linux commands that I admit that I never really understood fully for the last 20+ years.
$ man ln
in part says:
-n, --no-dereference
treat LINK_NAME as a normal file if it is a symbolic link to a directory
To try to understand this better, I broke this down as follows:
$ mkdir dir1
$ ln -vs dir1 dir2
'dir2' -> 'dir1'
$ mkdir dir3; touch dir3/xx
$ tree -F
.
├── dir1/
├── dir2 -> dir1/
└── dir3/
└── xx
Now to test -n, first as a hard link
$ ln -vn dir3/xx dir2
ln: failed to create hard link 'dir2': File exists
and second as a symbolic link
$ ln -vsn dir3/xx dir2
ln: failed to create symbolic link 'dir2': File exists
??? why do these both fail ???
Only the first command form in the SYNOPSIS calls out a 'LINK_NAME', in this syntax:
ln [OPTION]... [-T] TARGET LINK_NAME
So this says that the -n
and --no-dereference
options ONLY relate to the first command form for ln
, (and not the other three command forms).
In my example:
The TARGET is dir3/xx
, and
the LINK_NAME is dir2
('a symbolic link to a directory').
The manual says that if LINK_NAME (i.e. remember this is the name of the link we are supposedly creating) is 'a symbolic link to a directory'...
... then we are supposed to treat this symbolic link as a 'normal file'.
What am I missing?