3

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

7
  • 2
    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.
    – Wildcard
    Sep 7, 2017 at 3:49
  • This setup is a little bit odd, actually. I wonder what you use your "scripts" directory for? Not as part of your PATH, surely? (I wouldn't want an init script in my path lookup.)
    – Wildcard
    Sep 7, 2017 at 3:55
  • I just have a couple of scripts I sometimes use. Some of them I would like to run at startup. Sep 7, 2017 at 4:00
  • 1
    Yes. crontab, not contrab. The "tab" is for "table." And "cron" comes from "chronological" and relates to time.
    – Wildcard
    Sep 7, 2017 at 4:04
  • 1
    Yes. You should read the man page. man 5 crontab
    – Wildcard
    Sep 7, 2017 at 4:06

1 Answer 1

5

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.

1
  • 1
    Makes sense. Sorry for picking it so late. Had a lot on my head Sep 10, 2017 at 1:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .