Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Cannot overwrite an existing symbolic link

677 views
Skip to first unread message

Robert Langdon

unread,
Feb 29, 2008, 1:35:42 PM2/29/08
to
How could I create, in exact terms overwrite, an existing symbolic link
with ln?

According to the man page (let's have a look in the excerpt below) I
have to use the -f option.

If the link is an existing file, do not overwrite the
contents of the file. The -f option overrides this
option. This is the default behavior for /usr/xpg4/bin/ln,
and is silently ignored.

/usr/bin/ln
/usr/sbin/static/ln
/usr/xpg4/bin/ln
/usr/ucb/ln

No matter with which of the binaries above I am trying to overwrite an
existing symbolic link, I am getting an error. The environment is as
follows:

SunOS srvr2 5.9 Generic_122300-12 sun4u sparc SUNW,Sun-Fire-V440

rob@srvr2:~ $ touch source
rob@srvr2:~ $ touch 2ndsource
rob@srvr2:~ $ ln -s source foo
rob@srvr2:~ $ ln -s 2ndsource foo
ln: cannot create foo: File exists
rob@srvr2:~ $ ln -f -s 2ndsource foo
ln: cannot create foo: File exists
rob@srvr2:~ $ ln -n -f -s 2ndsource foo
ln: cannot create foo: File exists
rob@srvr2:~ $ ln -f -n -s 2ndsource foo
ln: cannot create foo: File exists

Thanks for any hints.

Regards,

Rob

Dick Hoogendijk

unread,
Feb 29, 2008, 3:39:52 PM2/29/08
to
quoting Robert Langdon (Fri, 29 Feb 2008 19:35:42 +0100):
> How could I create, in exact terms overwrite, an existing symbolic
> link with ln?

Remove and recreate it.

> According to the man page (let's have a look in the excerpt below) I
> have to use the -f option.

Yes, I know. But I've never got it to work form me.
So, I remove and recreate and that works fine ;-)

--
Dick Hoogendijk -- PGP/GnuPG key: 01D2433D
++ http://nagual.nl/ | SunOS 10u4 08/07 ++

Dave Uhring

unread,
Feb 29, 2008, 3:48:16 PM2/29/08
to
On Fri, 29 Feb 2008 21:39:52 +0100, Dick Hoogendijk wrote:

> quoting Robert Langdon (Fri, 29 Feb 2008 19:35:42 +0100):
>> How could I create, in exact terms overwrite, an existing symbolic
>> link with ln?
>
> Remove and recreate it.
>
>> According to the man page (let's have a look in the excerpt below) I
>> have to use the -f option.
>
> Yes, I know. But I've never got it to work form me.
> So, I remove and recreate and that works fine ;-)

Seems to be fixed in Nevada.

[duhring@einstein ~]$ uname -a
SunOS einstein 5.11 snv_82 i86pc i386 i86pc
[duhring@einstein ~]$ touch test
[duhring@einstein ~]$ touch test1
[duhring@einstein ~]$ ln -s test foo
[duhring@einstein ~]$ ln -s test1 foo


ln: cannot create foo: File exists

[duhring@einstein ~]$ ln -sf test1 foo
[duhring@einstein ~]$ ls -l foo
lrwxrwxrwx 1 duhring sysadmin 5 Feb 29 14:45 foo -> test1
[duhring@einstein ~]$ which ln
/usr/bin/ln

Dick Hoogendijk

unread,
Feb 29, 2008, 3:57:42 PM2/29/08
to

Hey nice to know that. Funny but because it never worked for me I never
took the change to try if things have changed. Sure they have, that
innovation, is it not. I'm running SXDE 1/08 on other machines (s10 is
just for the server). Just tried it on sxde4 and it works ;-)

Robert Langdon

unread,
Feb 29, 2008, 4:21:26 PM2/29/08
to
The background is, I have a cron job creating some logs on a daily
basis and would like to have a link on the newest one. Okay, I fixed it
already with a workaround using a tiny bash script which removes the
symbolic link if its existing. But hey, I thought I did something wrong
with my call as I could not imagine, that solaris have such bugs in
such basic commands and I have to invoke a second script with 5 lines
by cron just to overwrite an existing link.

But okay, the proof is the community. ;-)

Cheers,

Robert

Thommy M.

unread,
Feb 29, 2008, 4:36:26 PM2/29/08
to

I would call it evolution...

0 new messages