arrow_upward

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting up a Ubuntu-CentOS Server from scratch: Customize your shell
#1
*This tutorial is part of a series, visit the main thread to learn more*

When we own a server we basically interact with it via a terminal using SSH or something older then that. The bash prompt became something that we always see and read, so why don't customize it?

On this tutorial, we will learn how customize our bash prompt: how to change colors and how to add information that can useful on Ubuntu Server & CentOS.

Let's start with some information!

  • How works our bash prompt?
    Most Linux distro displays by default the hostname and the current working directory. Prompt's configuration is stored inside a special shell variable called PS1, there are other variables called PS2, PS3 and PS4 that we will not be used on this tutorial.
    So we can say that the PS1 variable is used as the primary prompt string and it is evaluated before each terminal update. To see our current bash's prompt configuration we can run the following command: 
    echo $PS1
    This configuration can be system-wide or user-specific, on this tutorial we will focus on user-specific customization.
  • Where is placed the bash's prompt configuration file?
    As we said above, the customization we will focus on is the user-specific one, so our bash prompt configuration file called ".bashrc", that contains the PS1 variable, is stored in the user's home:
    ~/.bashrc
    OR
    /home/{user}/.bashrc
  • What kind of customization can I configure?
    Well, let's start listing the customization that can add useful information to our bash:
    • A bell character:
      \a
    • An escape character:
      \e
    • A newline:
      \n
    • A carriage return:
      \r
    • A backslash:
      \\
    • A character whose ASCII code is the octal value nnn:
      \nnn
    • A character (like 'q' will print 'q'):
      {character}
    • If the user's uid is 0 it will print a '#', otherwise, if the user is 'root' it will print a '$':
      \$
    • The date in 'Weekday Month Date' format (like “Tue May 26”):
      \d
    • The time, in 24-hour HH:MM:SS format:
      \t
    • The time, in 12-hour HH:MM:SS format:
      \T
    • The time, in 12-hour am/pm format:
      \@
    • The time, in 24-hour HH:MM format:
      \A
    • The username of the current user:
      \u
    • The version of Bash (like 5.00):
      \v
    • The release of Bash, version and patchlevel (like 5.00.2):
      \V
    • The hostname, up to the first ‘.’ (like 'POST4VPS.FREEVPS.COM' will be displayes as 'POST4VPS'):
      \h
    • The hostname (like 'POST4VPS.FREEVPS.COM' will be displayes as 'POST4VPS.FREEVPS.COM'):
      \H
    • The number of jobs currently managed by the shell:
      \j
    • The basename of the shell’s terminal device name:
      \l
    • The name of the shell, the basename of $0 (the portion following the final slash):
      \s
    • The current working directory, with $HOME abbreviated with a tilde (like if you are on '/home/POST4VPS_tutorial' folder it will print '/home/POST4VPS_tutorial'):
      \w
    • The basename of $PWD, with $HOME abbreviated with a tilde (like if you are on '/home/POST4VPS_tutorial' folder it will print 'POST4VPS_tutorial'):
      \W
    • The history number of this command:
      \!
    • The command number of this command:
      \#
    • Begin a sequence of non-printing characters that can be used to embed a terminal control sequence into the prompt:
      \[
    • End a sequence of non-printing characters:
      \]
    The last two codes are really important because we will use them to set the colors and formatting configurations, the following codes need to be between the BEGIN and END snippets (like "\[ COLOR_FORMATTING_CODE \]"):
    • Reset the colors:
      \e[0m
    • Set text color as Black:
      \e[0;30m
    • Set text color as Red:
      \e[0;31m
    • Set text color as Green:
      \e[0;32m
    • Set text color as Yellow:
      \e[0;33m
    • Set text color as Blue:
      \e[0;34m
    • Set text color as Purple:
      \e[0;35m
    • Set text color as Cyan:
      \e[0;36m
    • Set text color as White:
      \e[0;37m
    • Set text as bold and text's color as Black:
      \e[1;30m
    • Set text as bold and text's color as Red:
      \e[1;31m
    • Set text as bold and text's color as Green:
      \e[1;32m
    • Set text as bold and text's color as Yellow:
      \e[1;33m
    • Set text as bold and text's color as Blue:
      \e[1;34m
    • Set text as bold and text's color as Purple:
      \e[1;35m
    • Set text as bold and text's color as Cyan:
      \e[1;36m
    • Set text as bold and text's color as White:
      \e[1;37m
    • Set text as underline and text's color as Black:
      \e[4;30m
    • Set text as underline and text's color as Red:
      \e[4;31m
    • Set text as underline and text's color as Green:
      \e[4;32m
    • Set text as underline and text's color as Yellow:
      \e[4;33m
    • Set text as underline and text's color as Blue:
      \e[4;34m
    • Set text as underline and text's color as Purple:
      \e[4;35m
    • Set text as underline and text's color as Cyan:
      \e[4;36m
    • Set text as underline and text's color as White:
      \e[4;37m
    • Set the text background color as Black:
      \e[40m
    • Set the text background color as Red:
      \e[41m
    • Set the text background color as Green:
      \e[42m
    • Set the text background color as Yellow:
      \e[43m
    • Set the text background color as Blue:
      \e[44m
    • Set the text background color as Purple:
      \e[45m
    • Set the text background color as Cyan:
      \e[46m
    • Set the text background color as White:
      \e[47m


    Now, we can start our tutorial:
    Opening file configuration:
    • MAKE A BACKUP of your .bashrc before starting editing it!
    • As we already said our bash prompt configuration file is located inside the current user folder, so we can open it using terminal editor, such as nano or vim, or graphical editors, such as gedit or sublime.


    Locate the PS1 variable and start customizing:
    • Scroll down until you locate the PS1 variable.
    • Add your own customization by mixing up all the above snippets of code.

    Examples:
    • I want to display username in yellow and hostname in red (Desired output: user@host:
      \[\e[0;33m\]\u\[\e[0m\]@\[\e[0;31m\]\h[\e[0m\]
    • I want to display the username is blue, hostname in purple and the current directory in bold and green:
      \[\e[0;34m\]\u\[\e[0m\]@\[\e[0;35m\]\h[\e[0m\]\[\e[4;32m\]\w

    Useful online tools:

    There are very useful online tools that can help you creating your own bash configuration:
    To see your customization enable just re-log into the system!

    Have fun!
Thanks to Post4VPS and Bladenodefor VPS 14
#2
Very useful, to change the style of your linux terminal shell!
 I want to ask!
Can it be made like this?

https://ibb.co/2PSwyTk
Terminal
Solo Developer
#3
(11-06-2019, 09:27 AM)chanalku91 Wrote: Very useful, to change the style of your linux terminal shell!
 I want to ask!
Can it be made like this?

https://ibb.co/2PSwyTk

Likely yes but there are two limitations:
  • You can't make a background color effect like that, the background color is applied in a "character area" basics.
  • You can't display images, the branch/fork symbol is not an ASCII character so you should replace it with something like the CHARACTER 204 (╠)
Thanks to Post4VPS and Bladenodefor VPS 14
#4
(11-06-2019, 09:38 AM)LightDestory Wrote: Likely yes but there are two limitations:
  • You can't make a background color effect like that, the background color is applied in a "character area" basics.
  • You can't display images, the branch/fork symbol is not an ASCII character so you should replace it with something like the CHARACTER 204 (╠)

ssh doesnt have an ability to display an image , it just basically dumb terminal in current day that can only show text . with a lot of custom character that have pixel per pixel probably you can make an image but that is very hard . just use vnc over a gui for image support
Terminal
humanpuff69@FPAX:~$ Thanks To Shadow Hosting And Post4VPS for VPS 5
#5
(11-06-2019, 02:49 PM)humanpuff69 Wrote: ssh doesnt have an ability to display an image , it just basically dumb terminal in current day that can only show text . with a lot of custom character that have pixel per pixel probably you can make an image but that is very hard . just use vnc over a gui for image support

Isn't this a useless/"just to increase my counter" reply? 
Did you even read my tutorial? When did I said that we were going to display images?
I have clearly listed almost every type of customization and there isn't any 'Image reference", just speaking about characters. 
On my reply regarding @chanalku91 question I have again clearly said that we can't displays images so he should think about replacing it with a symbol like '204' because it reassemble that particular image.
'Custom character that have pixel per pixel'... what? Again you didn't read the ASCII part of the tutorial.

Your suggestion about using a desktop remote technology is just no sense and out of contest.
Thanks to Post4VPS and Bladenodefor VPS 14



person_pin_circle Users browsing this thread: 1 Guest(s)
Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - Hyper Expert - Shadow Hosting - Bladenode - Hostlease - RackNerd - ReadyDedis - Limitless Hosting