How to create alias for a sub-folder to point to the parent folder?

I need to make a folder with name ./public/sop behave like it is ./public.

I tried ln -s ./public/ ./public/sop and there were no errors. But it doesn’t work. ls ./public/sop does not show the other files/folders in the ./public folder. It shows just one line:

lrwxrwxrwx 1 pi pi 9 Nov 20 13:06 public/sop -> ./public/

And an attempt to ls ./public/sop/test.txt, where test.txt is an existing file in ./public, returns No such file or directory.

How can I achieve what I need?

Asked By: Old Geezer


For this, you can use just . as the link target:

ln -s . ./public/sop

Then ./public/sop is effectively ./public/., which is just ./public itself.

You can see this in action in the Ubuntu repositories, where ubuntu is a link to ., so going to is effectively the same as

Answered By: muru
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.