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

2019-01-31 07:48发布

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 say to put a soft link, ln-s to the command line app in your /bin. That didn't work, so I just opened my ~/.profile and added an alias: alias subl="/Applications/path/to/subl". But that begs a new question for me. What is the difference between these two: alias and soft links?

7条回答
Lonely孤独者°
2楼-- · 2019-01-31 08:20

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.)

查看更多
登录 后发表回答