1

I don't know the term of the initial text before the command prompt of the console or the terminal, but the screen shot below should demonstrate well what I mean:

enter image description here

I want to reduce the highlighted text in the image: said@said-Satellite-L850-A700: to something like: said@pc or even to be only $ without any modification for the computer's name. Does it possible?

SaidbakR
  • 769

1 Answers1

2

You can control the prompt in Bash (and Zsh) by setting the PS1 environment variable.

You may do this in your $HOME/.bashrc file, for example.

Example:

PS1='\u@\h:\w\$ '

or for your-user@pc use

PS1='\u@pc'

or go simple

PS1='$ '

Here's some of the magic tokens you can use.

\h : the hostname up to the first ‘.’
\H : the hostname
\u : your username
\t : time in 24hr format
\w : current working dir

You can apply colour codes too, should you wish.

EDIT: colour, bold etc.

ANSI escape sequences can be specified like \033[ then some numbers for bold and colours joined with ; then m and can be reset with \033[0m;

e.g. PS1='\033[31mxxx\033[0m ' would give you a red xxx as a prompt.

Very mini cheatsheet, replace 31 (Red) in the above with..

  • 1;31 for bold red
  • 1 for bold default colour
  • 31;43 for red text (31) on yellow background (43). The second, background colour uses the same code as the foreground but +10
  • 38;2;r;g;b where you replace r g and b with a value 0-255 for red green blue, e.g. 38;2;255;180;0 would set it to a nice orange

PS1='\033[31mxxx\033[0m ' would give you a red xxx as a prompt.

Please see an excellent answer at stackoverflow for a fuller list.

artfulrobot
  • 8,543