Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

dry

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?

like image 359
Magnus Avatar asked Jan 09 '23 04:01

Magnus


1 Answers

You can just use "-f".

ln -sf /var/better orig

From man ln

-f, --force remove existing destination files

like image 131
Vivek Avatar answered Feb 02 '23 09:02

Vivek