0

终端中这两条线有什么区别?

Ms-MacBook-Pro:/ John$

Ms-MacBook-Pro:~ John$
4

2 回答 2

3

/ 是文件系统的根目录。因此,您的第一个提示意味着您当前位于文件系统的根目录中,并且您的名字是 John:

pwd
/
ls
usr var lib bin home etc ...

~ 是您的主目录(通常是 /home/John)。所以第二个提示意味着你当前在你的主目录中,你的名字是 John。

pwd
/home/John
ls
Downloads Desktop Documents Pictures ...

如果您的系统上有一个名为“tomas”的用户,那么 ~tomas 表示他的主目录,通常是 /home/tomas。

于 2016-06-16T17:51:19.870 回答
2

The meaning of anything that appears in your shell prompt depends on the value and interpretation of the $PS1 variable.

Type

echo "$PS1"

to see the string from which your displayed prompt is derived, and read the Bash manual (assuming your login shell is bash) to see how it's interpreted.

To see the bash manual, type info bash or go here. The interpretation of $PS1 is documented in the "Controlling the prompt" section under "Bash features" (section 6.9 in the latest version).

Most likely you have either \w or \W in your $PS1. \w expands to

The current working directory, with $HOME abbreviated with a tilde (uses the $PROMPT_DIRTRIM variable).

and \W expands to

The basename of $PWD, with $HOME abbreviated with a tilde.

The basename is the last component of the path, so for example /foo/bar would be displayed as /foo/bar with \w, or just as bar with \W.

In your case, the first prompt:

Ms-MacBook-Pro:/ John$

probably means you're currently in the root directory, and the second:

Ms-MacBook-Pro:~ John$

means you're in your home directory.

于 2016-06-16T18:12:55.603 回答