Background
In Linux (and Unix in general), there is a SuperUser named Root. The SuperUser can do anything and everything, and thus doing daily work as the SuperUser can be dangerous. You could type a command incorrectly and destroy the system. Ideally, you run as a user that has only the privileges needed for the task at hand. In some cases, this is necessarily Root, but most of the time it is a regular user.
su -
This command is used to login at root account.
By default, the Root account password is locked in Ubuntu. This means that you cannot login as Root directly or use the su command to become the Root user. However, since the Root account physically exists it is still possible to run programs with root-level privileges. This is where sudo comes in - it allows authorized users (normally "Administrative" users) to run certain programs as Root without having to know the root password.
See How to Enable Root Account.
sudo sh
This command runs "sh" as a super user.
The sh utility is a command language interpreter that shall execute commands read from a command line string, the standard input, or a specified file.
sudo bash
This command runs "bash" as a super user.
Bash is the shell, or command language interpreter. Bash is an sh-compatible shell that incorporates useful features from the Korn shell (ksh) and C shell (csh). It is intended to conform to the IEEE POSIX P1003.2/ISO 9945.2 Shell and Tools standard. It offers functional improvements over sh for both programming and interactive use. In addition, most sh scripts can be run by Bash without modification.
References: 1, 2, 3.
One difference is that /etc/environment
contains only variable definitions and doesn't appear to go through any sort of variable expansion/interpolation. Thus, you can't reference variables in definitions. This for instance won't work:
A="else"
B="something $A"
B will literally be something $A
, not the expected something else
.
See this question.
By the way, the answer you found through Google appears to be referring to a user's ~/.bashrc
, rather than the system-wide /etc/bash.bashrc
. That may be causing your confusion.
Best Answer
In short, if the screen shows a dollar sign (
$
) or hash (#
) on the left of the blinking cursor, you are in a command-line environment.$
,#
,%
symbols indicate the user account type you are logged in to.$
) means you are a normal user.#
) means you are the system administrator (root).%
).There are differences on prompts in different Unix or GNU/Linux distributions because of their default settings. For example, the prompt of Debian/Ubuntu is
guest@linux:~$
, the one of Fedora/CentOS/RedHat is[guest@linux ~]$
and the one of SuSE Linux/OpenSUSE isguest@linux:~>
. In general, the prompt usually show the login user name, machine hostname, and current working directory and ended with a dollar ($), percentage (%), or hash (#) sign.guest
- username: the user account you are logged in to.linux
- machine hostname: the machine you are operating.~
- current working directory: the directory you are in. Tilde (~
) means home directory, i.e. the default directory when first logging in.Reference: wiki.debian.org.hk/w/Basic_Command_Line