Tabla de contenido
In this article we are going to see some examples to customize the terminal prompt. The terminal Prompt is the command line that appears on the screen when we open a terminal. Its function is to facilitate access to system commands and allow us to execute them quickly and easily. The Prompt also displays information about the user and the directory we are in.
Although the terminal Prompt is configured by default, we can customize it in different ways to adapt it to our needs and preferences. In this article we show you some examples of how to customize the terminal Prompt in Linux.
Customizing the Prompt
Here are 6 examples
Change Prompt color
We can change the color of the terminal Prompt using the PS1 command. For example, to change the color of the Prompt to red, we can use the following command:
PS1='\[\e[1;31m\]\u@\h:\w\$\[\e[0m\] '
This command changes the color of the Prompt to red and displays the user name, the host and the directory we are in.
Add time and date
We can add the date and time to the terminal Prompt using the PS1 command. For example, to display the date and time in the Prompt, we can use the following command:
PS1='\[\e[1;34m\]\D{%T} \w\$\[\e[0m\] '
This command adds the date and time in blue to the Prompt and displays the directory we are in.
Add line number
We can add the line number to the terminal Prompt using the PS1 command. For example, to display the line number in the Prompt, we can use the following command:
PS1='\[\e[1;33m\]\D{%T} \w\$\[\e[0m\] '
This command adds the line number in yellow to the Prompt and displays the directory we are in.
Add line number and time
We can add both line number and time to the terminal Prompt using the PS1 command. For example, to display the line number and time in the Prompt, we can use the following command:
PS1='\[\e[1;32m\]\D{%T} \w\$\[\e[0m\] '
This command adds both the line number and the time in green to the Prompt and displays the directory we are in.
Show the directory in which we are located
We can display the directory we are in in the Prompt of the terminal using the PS1 command. For example, to display the directory we are in in the Prompt, we can use the following command:
PS1='\[\e[1;35m\]\D{%T} \w\$\[\e[0m\] '
This command displays the directory we are in in purple in the Prompt and also displays the time.
Display the user name and host
We can display the user name and host in the terminal Prompt by using the PS1 command. For example, to display the username and host in the Prompt, we can use the following command:
PS1='\[\e[1;36m\]\u@\h:\w\$\[\e[0m\] '
This command displays the user name and host in light blue in the Prompt and also shows the directory we are in.
We hope you found these examples of how to customize the Terminal Prompt in Linux useful. Remember that you can use these commands to customize the Terminal Prompt to your liking and adapt it to your needs. Go ahead and try them!