ericosg ericosg - 2 months ago 6
Linux Question

Convert file or directory to symbolic link and preserve permissions

I have

/home/eric/public_html
with
drwxr-x--- eric:nobody
as the mod and ownership.

I login with
eric
so I cannot recreate this folder without root access, since
eric
is not part of the
nobody
group.

I want to replace my
public_html
with a symbolic link (i.e.
ln -s ~/git/project/src ~/public_html
) but if I do that, my new
public_html
ends us without the correct permissions.

Is there a trick to get around this without contacting my admin?

Answer

Possibly by doing the following:

  1. Copy everything from ~/git/project/src into ~/public_html
  2. mv ~/git/project/src ~/git/project/src2 to get it out of the way
  3. mv ~/public_html ~/git/project/src
  4. finally link it back: ln -s ~/git/project/src ~/public_html

The idea is to keep the original public_html directory because it has the correct owner/permissions, but reuse it as the link target.