I have two directories in my home:
~/dir2 with a file in the first:
~/dir1/file.txt Is there any way that I can make a symlink to it from
~/dir2 without moving to
~/ and if not why is that the case?
I've tried from
$ ln -s ./dir1/file.txt ./dir2/file.txt
but as I'd expect, that causes the resultant symlink to effectively point at
~/dir1/dir2/file.txt which makes sense but isn't what I actually want.
I've also tried:
$ ln -s ./dir1/file.txt ../dir2/file.txt
ln: failed to create symbolic link `../dir2/file.txt': No such file or directory
I'd expect this to just create a symlink
~/dir2/file.txt pointing to
So I suppose my real question is this: can I force
ln to make a symlink to a file that it doesn't think exists?
Edit: For extra clarity as to what I'm trying to achieve, I want a single command that I can run from my home directory that will effectively do:
pushd dir2/ && ln -s ../dir1/file.txt && popd
or in Python (this is the closest I've come to what I want):
echo "import os; os.symlink('../dir1/file.txt', './dir2/file.txt')" | python