1

Sorry for the vague title.
I have a folder /opt/A/B/ and ideally, I want to symlink ~/B to /opt/A/ such that ~/B and /opt/A/B are in sync.
The obvious answer would be:

sudo rm -r /opt/A/B
sudo ln -s ~/B /opt/A/B

However, consider this scenario:
A is owned by root, but B is owned by me, and I don't want to use sudo (this operation is a python script that gets run by a very big thing that doesn't have sudo).

This is another approach (remember, I have ownership of /opt/A/B/):

ln -s ~/B/* /opt/A/B/

But then it will go out of sync if new directories/files get written in /opt/A/B or ~/B.

So my question is the following:

Is there any sudo-less way to do this?

I can use sudo for any one-time only operations that will not go in the script. If it matters, the goal is to rotate the symlink depending on certain configurations, so I do have a finite amount (specifically 3). Note: Can also be

testeaxeax
  • 1,506
C. Sano
  • 13
  • 3

1 Answers1

1

One-time sudo operation:

sudo ln -s ~/Z /opt/A/B

But now the trick to rotate configs. Let ~/Z be a symlink as well:

ln -s ~/B ~/Z  # it points to B
rm ~/Z
ln -s ~/C ~/Z  # now it points to C

Your different configs would be in B, C etc.