I'm using Fedora 26. I want a script to run at startup, but also have this script in my scripts folder. How can I make it so the /etc/init.d/foo
gets updated when I edit ~/scripts/bar
? I was thinking about a symbolic link, but i don't really know how to get it going
1 Answer
Symlinks are pretty straight forward, but you need to understand the changes are bi-directional, a change to the content of the symlink affects the original file and vice versa. That's because the symlink is really just a pointer to the original file and when you open a symlink your application silently opens the original instead.
If that's what you want, just do (from the terminal):
ln -s /PATH/TO/TARGET/FILE /PATH/TO/NEW/SYMLINK
You don't need a script to update the symlink then. You can also create relative symlinks by making the path to the target file a relative path (as viewed from where the symlink will be kept). Like so:
cd /home/myuser/folder1/folder2
ln -s ../file-in-folder1 symlink-in-folder2
but if you then move your symlink to another directory it will break it's reference to the original file.
You can view where symlinks link to with the long output from ls:
ls -l /PATH/TO/SYMLINK
or ls -l /PATH/TO/DIRECTORY/WITH/SYMLINKS/IN/IT
You can also make symlinks to directories themselves. Same rules apply. Only difference from normal directories is that you don't have to recurse them with the -r
flag when removing them with rm
. Cause they aren't really a directory... they are a file that points to a directory.
-
1Makes sense. Sorry for picking it so late. Had a lot on my head Sep 10, 2017 at 1:35
ln -s /etc/init.d/foo ~/scripts/bar
—and please don't do it the other way around in production code. Init scripts should be owned by root.crontab
, notcontrab
. The "tab" is for "table." And "cron" comes from "chronological" and relates to time.man 5 crontab