Tailoring your Linux command prompt

Uncategorized

The command prompt in a Linux terminal window is frequently just a$ unless you’ve visited or sudo’ed your method into the root account, in which case you ‘d expect a #.

Often, however, your prompt will be more complicated, with a format like [lucky@fedora ~] $. But it’s possible to alter your timely to some friendlier character, word, or expression, and if you’re so likely, you can even alter its color. This post shows how easy it is to make these type of changes.Changing the format To get going, something you require to know is that your command timely is not just something your shell creates on the fly. Rather, it’s a variable and its name is PS1. To see how your timely is defined, show its value like this:- bash-5.1$echo$ PS1 s- v $In the case shown above, the timely consists of the name of the shell( celebration)and its variation (5.1). That’s what those letters ( s and v)suggest when you look at how it’s defined. To change to this format, you would utilize a command like this: $ PS1=” s- v $”

Another often-used timely format includes the username and hostname as in the example listed below.

[jdoe@fedora ~] $ echo $PS1 [ u@h W] $

You would use a command like the one below to change your prompt to this format.

PS1=” [ u@h W] $”

To alter to merely a dollar sign, do this:

$ PS1=”$”

Bear in mind that the blank at the end of these prompt definitions is needed to separate the prompt from the commands that you will be typing.

Altering the text

While many Linux users stick with one of the standard triggers, there’s nothing that says you must. If you prefer a “>” or a “?”, that will work.

$ PS1=”>” $ PS1=”?”

In fact, you can be imaginative with your prompt.

$ PS1=”What now? >” $ PS1=”Ready for a break? >”

To alter your prompt to include the date in mm/dd/yy format, use a command like this one:

PS1=”‘date +%D’>”

Changing the color

To change your timely to a different color, you have to first identify the color you wish to use and express it to bash or whatever shell you are using in a manner that it can understand. When I change my prompt to “yes? >” in a lively purple font, I use a command like this:

PS1=” [ 033 [10; 95m ] yes? > [ 033 [0m ]

The [ 033 [10; 85m] string alters the font color to purple and the [ 033 [0m ] modifications it back so that only my prompt handles the new color, clearly differentiating it from whatever else that I type on the command line.Changing your.bashrc file It is necessary to remember

that you need to conserve your new timely definition in your.bashrc(or other shell start-up)file to maintain the changes. Add it to the end to override any other timely meanings. For example:

yes? > echo PS1='” [ 033 [10; 95m ] yes? > [ 033 [0m ]’ >> ~/. bashrc yes? > tail -1 ~/. bashrc PS1=” [ 033 [10; 95m ] yes? > [ 033 [0m ]

And here are some other colors that you can choose from:

black=’ 0; 30 [0m’ lightgray=’ 033 [37m’ red=’ 033 [31m’ blue=’ 033 [34m’ lightgreen=’ 033 [32m’ reset=’ 033 [0m’ cyan=’ 033 [36m’ orange=’ 033 [33m’ white=’ 033 [37m’ darkgray=’ 1; 30m’ pink=’ 033 [31m’ green=’ 033 [32m’ purple=’ 033 [35m’

Wrap-Up

The command prompt in a Linux terminal window is as flexible as you want it to be, and making modifications is surprisingly simple. Simply do not forget to add your brand-new PS1 format to the end of your.bashrc file.

Copyright © 2023 IDG Communications, Inc.

. Source

Leave a Reply

Your email address will not be published. Required fields are marked *