What is a Symlink?
A symlink or a Symbolic Link is simply enough a shortcut to another file. It is a file that points to another file.
They may sound a little complex, but they're really not, you can think of symlinks as shortcuts. To create a symbolic link you use the following command:
ln -s target_path link_path
# Example
sudo ln -s /usr/bin/pip3 /usr/bin/pip
Here's a quick example
Say that we have a folder on our Desktop called rad_folder
and inside that folder is a file called cool.txt
. In order to create a symlink that points to our rad_folder
, we could do that with the following command:
ln -s ~/Desktop/rad_folder ~/Desktop/awesome_link
After running that command we will have a new symlink (shortcut) called awesome_link
on our Desktop. If you go into that link:
cd ~/Desktop/awesome_link
And list out the contents in our shortcut we will see a file called cool.txt
. This is because we are pointing to the rad_folder
when we go into the awesome_link
symlink.
Note, if we were to print out our current working directory pwd we will get the full path to the symlink /Users/tony/Desktop/awesome_link/, so it may appear to be a folder, but it's not.
And that's it. They're pretty simple! From here on out when you hear the term symlink you can think of shortcut and you should be on the right path