Tuesday 5 February 2013

Changing Command Prompt in Linux

Problem: Changing Command Prompt in Linux.
Solution: By default when you logged into terminal. You will see prompt as "[root@mydesktop build]#" (i.e)
[user@hostname current-workingdir]#. If you want to change these prompt settings change the environment variable PS1

To know default value:
[root@mydesktop build]# echo $PS1
[\u@\h \W]\$
To change value:
[root@mydesktop build]#export PS1='[\u@dragon \W]\$'
[root@dragon build]#

The values are lost when terminal is closed. To persist values for ever update file "/root/.bashrc"
My Bash file:
[root@dragon ~]#cat .bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
export PS1='[\u@dragon \W]\$'


No comments:

Post a Comment