1. Introduction

In Unix-like environments, including Linux, we often use the command-line interface to perform many tasks. In these environments, we see a prompt before the cursor. This often includes the username, system name and some other information, and most notably a symbol such as “$” or “#”. In this tutorial, we’ll learn about the difference between these symbols in the context of command-line prompts.

2. The Meanings of $ and #

The symbols “$” and “#” in a prompt are used to differentiate between the type of user account we’re logged in as. Conventionally, the “$” symbol represents a regular user account, and the “#” symbol denotes only the root user. It’s as simple as that. Below, we’ll see a demonstration of how the prompt changes as we switch user accounts.

3. Demonstration

Let’s see how the symbol in the prompt changes as we switch from a regular user account to a root account. Note that we’re using Ubuntu 22.04 for this example:

kd@localhost:~$ whoami
kd

kd@localhost:~$ sudo su - root
[sudo] password for kd: 

root@localhost:~# whoami
root

root@localhost:~# exit
logout

kd@localhost:~$ whoami
kd

In the above example, we see that for the regular user’s prompt, the terminal shows the “$” sign. When we switch to the root user using the su (substitute user) command, we see that the terminal shows us the “#” sign. When we exit and switch back to the regular user, we see the “$” sign again. Also, we use the whoami command to view the name of the currently logged-in user.

On most Linux distros, we can also run a command as the root user while still keeping the “$” symbol at the prompt. We can use the sudo command for this:

kd@localhost:~$ sudo whoami
root

In the above example, we see that the whoami command prints “root” when we run it using sudo, though our prompt says that we’re logged in as our regular user (kd).

4. Changing the Prompt

We can modify the terminal prompt, including the “$” or “#” symbol, by modifying the PS1 environment variable. If we desire, we could also change the prompt for each user and make the change persistent, too.

5. Conclusion

In this article, we looked at the difference between “$” and “#” symbols in a terminal prompt. The “$” symbol is used for regular user accounts and “#” is used for root accounts. We also saw that the prompts change when we change user accounts. If we desire, we could also change the prompts.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.