What a DRYest way to replace a file with a symlink in bash

I have an existing file, which I replace with a symlink to another file. So I basically have to do this:

rm orig
ln -s /var/better orig

I DRYed above:

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

But it doesn't work anymore. Now the shell complains:

-bash: rm orig;: command not found

Is there a way to get DRY to work?

+4
source share
2 answers

You can just use "-f".

ln -sf /var/better orig

From man ln

-f, --force delete existing destination files

+8
source

All you need is cp:

cp -sf /var/better orig
+1
source

Source: https://habr.com/ru/post/1569330/


All Articles