A shell prompt is the text displayed by a command-line shell to show that it is ready to receive your next command.
For example:
user@linux:~$ or:
root@server:/var/www# It looks simple, but the prompt can tell you important information about who you are, where you are, and what shell environment you’re using.
Consider:
john@ubuntu:~/projects$ Each part has meaning:
john — the current username@ubuntu — the hostname of the computer~/projects — the current working directory$ — indicates a normal userA root user typically sees:
root@ubuntu:/var/www# The # usually indicates that the shell is running with root privileges.
This distinction matters because commands executed as root can modify or delete system files.
$ vs #One of the first things to recognize in a Linux shell is the final character.
john@ubuntu:~$ means you’re operating as a regular user.
root@ubuntu:~# means you’re operating as root.
For example:
rm important-file.txt might only affect files you have permission to modify.
But running commands as root can give you access to much more of the system.
Never assume # is just decoration.
When you run:
pwd you can see your current directory.
Suppose the result is:
/home/john/projects Your prompt might display:
john@ubuntu:~/projects$ Move somewhere else:
cd /var/log and it could become:
john@ubuntu:/var/log$ The prompt can therefore act as a quick reminder of where commands will be executed.
$PS1?In many shells, the primary prompt is controlled by a variable called:
PS1 You can inspect it with:
echo $PS1 You might see something like:
\u@\h:\w\$ These aren’t random characters.
Common Bash prompt escapes include:
| Code | Meaning |
|---|---|
\u | Username |
\h | Hostname |
\w | Current working directory |
\W | Current directory name |
\t | Current time |
\d | Current date |
\$ | $ for normal user, # for root |
So:
\u@\h:\w\$ can produce:
john@ubuntu:~/projects$ You can temporarily change your prompt:
PS1="shell> " Now you’ll see:
shell> You could include the current directory:
PS1="\w $ " giving:
~/projects $ Or include the username:
PS1="\u@\w $ " giving:
john@~/projects $ The change normally lasts only for the current shell session.
For Bash, your configuration is commonly stored in:
~/.bashrc You can edit it:
nano ~/.bashrc Then add your preferred PS1 configuration.
For example:
PS1="\u@\h:\w\$ " After saving, reload the configuration:
source ~/.bashrc Your customized prompt should now appear.
These two concepts are related but different.
Shell:
A program that interprets commands, such as:
Prompt:
The interface displayed by the shell when it is waiting for your command.
For example:
john@ubuntu:~$ is the prompt.
The program interpreting:
ls is the shell.
A well-designed prompt can provide useful context without requiring extra commands.
For example:
john@production-server:/var/www# immediately tells you:
User: john
Machine: production-server
Directory: /var/www
Privilege: root
That information can help prevent mistakes, especially when working across multiple servers or terminals.
A shell prompt isn’t merely decoration.
It is a status indicator for your command-line environment—and once you understand PS1, you can customize it to display exactly the information you need.
Latest tech news and coding tips.
A SOC Analyst (Security Operations Center Analyst) is one of the frontline defenders of an organization’s cybersecurity…
Most image upload systems assume one thing: the user has a stable internet connection. That assumption…
Imagine a user submits a form while their internet connection suddenly disappears. Normally, the request…
Cybercriminals don't always announce their presence. Many compromises are designed to remain unnoticed for weeks…
For years, jQuery was everywhere. If you were building websites in the 2010s, there was a…
Few things halt a developer’s flow faster than seeing the dreaded word: CONFLICT. A Git merge…