I have a folder on my HDD /media/kalenpw/HDD/Documents/ShellScripts
that is full of various scripts I would like to have accessible from any directory. My previous strategy was copying all of the files into /usr/local/bin
this worked, but was tedious when updating scripts having to change in two places.
Luckily, I recently learned about symlinks and they are the perfect fit.
I made a test script in my home folder
test.sh
print "Hello"
then I did ln ~/test.sh /usr/local/bin
and like expected I could execute test.sh
from anywhere.
The issue I'm having is I would prefer to keep all my documents on my HDD(at the directory given earlier). However, you can't link between drives so as expected I got an error
Invalid cross-device link
so I tried doing a symbolic link like so: sudo ln -s ./test.sh /usr/local/bin/
which created a link like expected. However, I can not execute test.sh
from any directory(or even at all) like I would like. To ensure the file didn't lose permissions in the linking from /usr/local/bin
I did sudo chmod +x ./test.sh
and got an error:
chmod: cannot access './test.sh': Too many levels of symbolic links
I can't imagine there isn't a way to do this as it seems like a common usage, but I couldn't figure out how.
Summary: how can I create a link from one file to another on a different physical drive and still retain the ability to execute the linked file.
ln -s ./test.sh ...
it does exactly that. If you dols -l /usr/local/bin/test.sh
, you will see the result:test.sh -> ./test.sh
, so it points to itself - giving an endless loop when referencing. When crossing borders, you always should use full path:sudo ln -s /full-path-to-dir/test.sh /usr/local/bin
will then work.