Setting Pretty Prompts in Linux
-
With so many people being new to Linux and discovering the command line and BASH for the first time, something that is likely going to be missed is setting pretty BASH prompts. There is a lot that you could learn about prompts but what I'm going to show is a simple, common and very useful BASH prompt change that will affect all system users.
The file that we want to change is /etc/profile. This is a universal file that controls all users' environments, so be aware that you will impact other people by doing this (which is exactly what I want in this case.)
You can use an editor like vi, pico, emacs, joe or nano to make this change (or any GUI tool if you have a GUI installed.) Simple edit the /etc/profile file and add a new line at the end that looks like this:
export PS1="\u@\h:[\w] $ "
Or if you want to do this with a single command and not have to go into the file to edit it you could do this command (be aware, this simply appends the change so if you do this a lot you will make a large file full of the same command):
echo 'export PS1="\u@\h:[\w] $ "' >> /etc/profile
After you do this you can log out and log back in to see your changes. Or we can "source" the profile right away to see the changes in our live environment. This is a little known trick and the command is simply the dot "." So we can do this...
. /etc/profile
-
I used to have a really complicated bashrc and bash_profile file, now I jsut don't gaive a damn. sanme reason i didn't spell check this.
-
What does adding that line do?
-
-
Makes my prompt look like this:
scott@cc-lnx-jump:[~/.ssh] $
-
User at server. Current Working Directory. $
You can option for less or more info there. This is the most I would recommend. But you could add the time, for example. Or the IP address. Or have nothing at all. I like knowing WHO I am and WHERE I am especially since I might be working as root or something.
-
I've done this in the past, though without looking it up I couldn't tell you how.