Operating a standard bash shell on a server, the PS1 prompt defaults to ending in a $ for non-root users, and # for root.
ubuntu@server:~$ sudo su root@server:/home/ubuntu#
Why is this?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
Historically the original /bin/sh Bourne shell would use
$ as the normal prompt and
# for the root user prompt (and csh would use
%). This made it pretty easy to tell if you were running as superuser or not.
# is also the comment character, so anyone blindly re-entering data wouldn't run any real commands.
More modern shells (eg ksh, bash) continue this distinction of
# although it's less important when you can set more complicated values such as the username, hostname, directory :-)
The POSIX standard says (my emphasis):
This variable is used for interactive prompts. Historically, the "superuser" has had a prompt of
#. Since privileges are not required to be monolithic, it is difficult to define which privileges should cause the alternate prompt. However, a sufficiently powerful user should be reminded of that power by having an alternate prompt.
See also this answer to virtually the same question on the SuperUser forum.