The Bash shell prompt is a crucial element of the Bash (Bourne Again Shell) command-line interface. It serves as a visual indicator, providing essential information about the current session and awaiting user input.
By default, the Bash prompt typically displays the following information:
A standard prompt might look like this:
username@hostname:~/current/directory$
One of the powerful features of Bash is the ability to customize the prompt. This is done by modifying the PS1 environment variable.
Sequence | Description |
---|---|
\u | Username |
\h | Hostname |
\w | Full working directory path |
\W | Current working directory |
\d | Date in "Weekday Month Date" format |
\t | Current time in 24-hour format |
To customize your prompt, you can modify the PS1 variable in your ~/.bashrc
file:
export PS1="\u@\h [\w]$ "
This will create a prompt that displays the username, hostname, and full working directory path.
For more advanced users, the prompt can include color codes, command execution results, or even Git branch information.
You can add colors to your prompt using ANSI escape codes:
export PS1="\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[00m\]\$ "
This creates a prompt with a green username and hostname, and a blue working directory.
To further enhance your Bash experience, explore these related topics:
By mastering the Bash shell prompt, you'll create a more efficient and personalized command-line experience, tailored to your specific needs and preferences.