What is bash prompt? Bash prompt is a like a bridge connects you to the shell. Bash prompt is a place where you type a command to ask the shell to perform a task. Bash prompt is usually represented by a dollar sign "$".
By default, Ubuntu and its derivative has bash prompt with the following format:
The above bash prompt format can be divided into three parts:
- hok00age@Laptop-Q:~$
1. The word "hok00age" is username who types the command.
2. The word "Laptop-Q" is the hostname of the computer.
3. The character "~" is the working directory of current shell.
Today, I'd like to show you how to change this bash prompt format into something like this:
The first part of the above format "[08:47:50]" is the current time of the computer.
- [08:47:50][hok00age]:~$
How to do that? Simply type the following command on currently opened Terminal:
Please pay attention on the above command. The part who will become "current time" in bash prompt is "\t", "\u" will become username, and you can guess that "\w" will become working directory. The key of this trick is bash prompt special characters to display any information on the shell. You can see all of available special characters that can be used to modify bash prompt here.
- export PS1="[\t][\u]:\w\$ "
Please note, that any modifications you've made only affect the currently active shell. In other words, if you open a new Terminal emulator window, bash prompt is still in Ubuntu default. To make it permanent, you have to edit ".bashrc" file located in home directory. Open it with your favorite text editor or simply type the following command:
All you need to do is adding export PS1="[\t][\u]:\w\$ " line to the end of .bashrc file (see the figure below):
- gedit ~/.bashrc
Now save the change and test it by opening new Terminal window.
Regards :)
0 comments:
Post a Comment