1

It's possible that making a symbolic link is not at all comparable to making an alias. But from what I understand about symbolic links so far, they do the same thing as setting an alias: they define a new command that you can enter into your terminal to execute something with a different name

When should you make an alias and when should you make a symbolic link?

3

An alias can include options and arguments, letting you set your preferred default options for a command:

alias ll='ls -l'

and has nothing to do with files.

A symbolic link creates an entry in the file system that refers to some other file in the file system:

link -s ~/somedirectory/mydoc.txt ~/someotherdirectory

will create a link in someotherdirectory to mydoc.txt

However.

If a link is used for an executable file then it can give a new name for a command, just as alias can. For instance on my system ls -l /usr/bin/vi says

lrwxr-xr-x  1 root  wheel     3B 19 Nov  2019 /usr/bin/vi -> vim

So now vi is an executable command that is identical to vim. Similarly, many systems have both python2 & python3 installed, and then python will be symlink to one of them.

In practise the biggest difference is usually:

  • aliases are defined in your profile scripts, they are usually specific to you and they only work in the shell.
  • When an executable is linked to a new name in a bin directory then it's a system command available to all processes and users
  • Thank you! I've never thought about this before, but what significance does making a symbolic link to a non-executable have? In terms of your example, what purpose would a link to mydoc.txt in someotherdirectory serve? – James Ronald Aug 11 '20 at 0:12
  • 1
    @JamesRonald It would useful if there was a script or an application that was set to write to a file that's in a certain directory. For example, there can be a script with many lines that write to /new_data/chemistry/experiments/type_1 but if the file is moved elsewhere such as /new_data/chemistry_1/experiments/type_1, and one doesn't want to alter the script, then one can create a symbolic link in the old directory that points to the file in the new directory. – Nasir Riley Aug 11 '20 at 0:39
  • 1
    @JamesRonald Debian-based Linux systems also use symlinks extensively for the "alternatives" mechanism. – AdminBee Aug 11 '20 at 6:46
  • @NasirRiley That is crazy useful, thanks so much! – James Ronald Aug 11 '20 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.