Der Prompt einer Linux CLI Sitzung kann nach den eigenen Bedürfnissen angepasst werden.

Linux und Unix Systeme unterscheinden zwischen zwei benutzer in der Ausführung des Prompts:

 

  • der root benutzer hat vor der Einagbe ein # stehen
  • alle anderen haben üblicherweise ein $ stehen

 

Das Aussehen des Promptes kann aber über die Variable PS1 eingestellt werden.
Alle Veränderungen die direkt in der Befehlszeile einer Sitzung gemacht werden sind nur für diese gültig, erst das Eintragen in einer Startup Datei (z.B. .profile) macht dies permanent.

Also keine Angst beim ausprobieren.

 

Unter Linux ist der Standard Promot schon so eingestellt, dass mehr als der # bzw. $ zu sehen ist, z.B könnte er so aussehen:

[root@pappel /]#

 Wenn wir nun ein echo $PS1 eingeben

[root@pappel /]# echo $PS1
[\u@\h \W]\$

können wir die aktuelle Einstellung sehen.

Es fällt auf, dass wir Angaben wie \u und \h sehen.
Dies sind Kombinationen die von der Shell erkannt und durch ihre Bedeutung, bei jeder neuen Ausgabe des Promptes, ersetzt werden.

  • \u ergibt den Benutzername (User)  hier root
  • \h ergibt den Rechnernamen (Host)  hier pappel
  • \W ergibt den aktuelle Verzeichnisnamen ohne Struktur  (Working directory)  hier ist es /
  • \$ ergibt bei normalen Benutzern ein $ bzw bei root ein #

 

So kennt die bash diese Kombinationen  (man bash):

 

             \a     an ASCII bell character (07)
              \d     the date in "Weekday Month Date" format (e.g., "Tue May 26")
              \D{format}
                     the format is passed to strftime(3) and the result is inserted into the  prompt  string;  an  empty  format
                     results in a locale-specific time representation.  The braces are required
              \e     an ASCII escape character (033)
              \h     the hostname up to the first `.'
              \H     the hostname
              \j     the number of jobs currently managed by the shell
              \l     the basename of the shell's terminal device name
              \n     newline
              \r     carriage return
              \s     the name of the shell, the basename of $0 (the portion following the final slash)
              \t     the current time in 24-hour HH:MM:SS format
              \T     the current time in 12-hour HH:MM:SS format
              \@     the current time in 12-hour am/pm format
              \A     the current time in 24-hour HH:MM format
              \u     the username of the current user
              \v     the version of bash (e.g., 2.00)
              \V     the release of bash, version + patch level (e.g., 2.00.0)
              \w     the  current  working  directory, with $HOME abbreviated with a tilde (uses the value of the PROMPT_DIRTRIM
                     variable)
              \W     the basename of the current working directory, with $HOME abbreviated with a tilde
              \!     the history number of this command
              \#     the command number of this command
              \$     if the effective UID is 0, a #, otherwise a $
              \nnn   the character corresponding to the octal number nnn
              \\     a backslash
              \[     begin a sequence of non-printing characters, which could be used to embed a terminal control sequence  into
                     the prompt
              \]     end a sequence of non-printing characters

 

Will man den Prompt neu setzen, so muss man einfach der Varaiblen PS1 einen neuen Wert zuweisen (hier als Benutzer tom):

 

[tom@pappel ~]$ PS1='\u | \w \$ '
tom | ~ $ cd /tmp
tom | /tmp $

 

Farbige Ausgaben können im Prompt über

 

\[\033[0;30m\] schwarz
\[\033[1;30m\] dunkelgrau
\[\033[0;31m\] rot
\[\033[1;31m\] helles rot
\[\033[0;32m\] grün
\[\033[1;32m\] hellgrün
\[\033[0;33m\] braun
\[\033[1;33m\] gelb
\[\033[0;34m\] blau
\[\033[1;34m\] hellblau
\[\033[0;35m\] dunkellila
\[\033[1;35m\] helllila
\[\033[0;36m\] Dunkeltürkis
\[\033[1;36m\] Türkis
\[\033[0;37m\] Hellgrau
\[\033[1;37m\] weiß
\[\033[0m\] farblos

 

 bzw den Hintergrund durch

\[\033[XXm\] Keine
\[\033[40;XXm\] Schwarzer
\[\033[41;XXm\] Roter
\[\033[42;XXm\] Grüner
\[\033[43;XXm\] Hellbrauner
\[\033[44;XXm\] Blauer
\[\033[45;XXm\] Lila
\[\033[46;XXm\] Türkis
\[\033[47;XXm\] Hellgrau

 

 erzeugt werden.

tom | ~ $  PS1='\[\033[1;31m\]\u\[\033[0;38m\] \w \$ '
tom ~ $