Magnus
Magnus

Reputation: 11426

What's the DRYest way to replace a file with a symlink in bash

I have an existing file which I'm replacing with a symlink to another file. So I basically need to do this:

rm orig
ln -s /var/better orig

I DRYed the above to this:

{rm,ln\ -s\ /var/better}\ orig\;

But it no longer works. The shell now complains:

-bash: rm orig;: command not found

Is there a way to make the DRY form work?

Upvotes: 4

Views: 72

Answers (2)

Vivek
Vivek

Reputation: 2020

You can just use "-f".

ln -sf /var/better orig

From man ln

-f, --force remove existing destination files

Upvotes: 8

Hans Klünder
Hans Klünder

Reputation: 2292

All you need is cp:

cp -sf /var/better orig

Upvotes: 1

Related Questions