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

后端 未结 7 2056
佛祖请我去吃肉
佛祖请我去吃肉 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:16

    It is really a super question

    There are 3 levels of aliases in this debate

    1. File system: ln -s "target-file-or-directory" "alias" - this is visual for all programs using the file system (bash, Finder, applications)
    2. Shell alias: (bash/sh/zsh etc) - (part of question) - only used by shell command line
    3. MacOS Finder: "make alias" - Known by Finder, and file dialogue box in most applications

    Some different use cases:

    • Want shell scripts (bash) to navigate your file system in a symbolic way - then use ln -s ... When you install java it will use this technique it self. In example try to say which java and see where java is. Then use ls -a /usr/bin/java to see where is really is.
    • Want to do fast links in Finder so you can navigate to common things that happens to be located in different directories --> use Finder make alias
    • Want to start Sublime editor with a short cut from bash then use Shell alias. I have alias ll=ls -l - that lists a directory one item per line. I hardly cannot use bash without it :-) Note these substitutions only takes place on the command line substitution in bash and is therefore less useful in shell scripts.

    Personally I use ln -s .. relative often.

    I also use Finder make alias a lot. It is easy and links follows the items as they more around. But it does not work from bash - therefore I sometimes changes these links to **ln -s ...* when I need to start scripting.

提交回复
热议问题