What's the difference between ln -s and alias?

后端 未结 7 2053
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-23 09:42

I just found a workaround for a problem I was having with the subl command for Sublime Text 3 when the MacPorts version of python is installed. The instructions

7条回答
  •  死守一世寂寞
    2020-12-23 10:12

    They're entirely different things, though in this case they can be used for similar purposes.

    This:

    alias subl="/Applications/path/to/subl"
    

    creates an alias, so that typing subl as a shell command is equivalent to typing /Applications/path/to/subl.

    In bash, functions are generally preferred to aliases, because they're much more flexible and powerful.

    subl() { /Applications/path/to/subl ; }
    

    Both these things are specific to the shell; they cause the shell to expand sub1 to a specified command.

    ln -s, on the other hand, creates a symbolic link in the file system. A symbolic link is a reference to another file, and for most purposes it can be treated as if it were the file itself. It applies to anything that accesses it, not just to the shell, it's immediately visible to all processes running on the system, and it persists until it's removed. (A symbolic link is implemented as a small special file containing the name of the target file.)

提交回复
热议问题