[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug in ln re -f option
From: |
Bob Proulx |
Subject: |
Re: Bug in ln re -f option |
Date: |
Sat, 4 Oct 2003 18:28:48 -0600 |
User-agent: |
Mutt/1.3.28i |
Darren Besler wrote:
> Using Redhat Linux 8.0, fileutils rpm: fileutils-4.1.9-11.
Or any BSD variant. But SysV is the other way.
> I have observed that the ln -f option does not work as prescribed
> when target is a directory.
I have hit that several times myself. It is BSD like behavior. I
think you are wanting SysV behavior.
> # mkdir aaa
> # ln -s aaa bbb
> # mkdir aaaa
> # ln -sf aaaa bbb
> # ln -s aaaa bbb
> ln: `bbb/aaaa': File exists
Symlinks are completely transparent at this moment. Which means that
if you have a symlink to a directory the new symlink does not replace
the old symlink but instead is created in the directory. This is what
would happen if you were using 'cp' or 'mv' and the target were a
symlink.
You will need to add the -n option to ln -s.
mkdir aaa
ln -s aaa bbb
mkdir aaaa
ln -sfn aaaa bbb
ln -sfn aaaa bbb
ln -sfn aaaa bbb
ln -sfn aaaa bbb
-n, --no-dereference
treat destination that is a symlink to a directory
as if it were a normal file
The BSD man page says this:
-h If the target_file or target_dir is a symbolic link, do not follow
it. This is most useful with the -f option, to replace a symlink
which may point to a directory.
-n Same as -h, for compatibility with other ln implementations.
So -n is the lowest common denominator. But it does not work on SysV
systems such as HP-UX. So it is not portable.
The best you can do for portable scripts is to remove the symlink
first and then make it. A two step process.
rm -f bbb
ln -sf aaaa bbb
Bob