Symbolic Links
A symbolic link allows you to create what appears to be a new file but which points to an existing file. The command is:
$ ln -s /path/to/file /path/to/link
This creates a symbolic link /path/to/link
which points to /path/to/file
.
It can be very handy to have multiple copies of a file in different places. For example, you might have a binary with a long name, such as python3.8, but it would be easier to call it python. You can use a symbolic link so that /usr/local/bin/python3.8 points /usr/local/bin/python:
$ doas ln -s /usr/local/bin/python3.8 /usr/local/bin/python
This creates a symbolic link /usr/local/bin/python
which points to /usr/local/bin/python3.8
.
If you long list it without following symbolic links:
$ ls -ld /usr/local/bin/python
lrwxr-xr-x 1 root wheel 24 Feb 25 07:13 /usr/local/bin/python -> /usr/local/bin/python3.8
The -> indicates that /usr/local/bin/python
is a symbolic link.
Symbolic links can be used on folders, too# This can be very handy:
$ doas ln -s /var/www/htdocs /home/username/htdocs
Now, any files you put in your home folder's htdocs will automatically show up in /var/www/htdocs (the folder for your web server).