May 17, 2008

Bash configuration files

Bash configuration files

The bash controls some special files, which are part of every user's profile. These files are sitting right in your home directory.

[agustin@server2 agustin]$ ls .bash*

File name

Description

.bash_history

Keeps a list of the commands you have been typing

.bash_logout

A list of auto run commands to be executed when you leave the shell,

.bash_profile

A list of commands to be executed when you log in.

.bashrc

contains a list of commands that is executed every time you open a new shell

Changing the prompt

This is not so important it is just a matter of personal taste. Here I will demonstrate how to modify the prompt. This modification is for general users, and the file to be modified is /etc/bashrc

[root@server2 agustin]# vi /etc/bashrc

1 # /etc/bashrc
2 
3 # System wide functions and aliases
4 # Environment stuff goes in /etc/profile
5
6 # by default, we want this to get set.
7 # Even for non-interactive, non-login shells.
8 if [ `id -gn` = `id -un` -a `id -u` -gt 99 ]; then
9       umask 002
10 else
11      umask 022
12 fi
13
14 # are we an interactive shell?
15 if [ "$PS1" ]; then
16    case $TERM in
17      xterm*)
18          PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
19          ;;
20      *)
21          ;;
22    esac
23 #   [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
24    
25    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="\[\e[1;32m\] \w\\$\[\e[1;37m\]"
26  
27    if [ -z "$loginsh" ]; then # We're not a login shell
28        for i in /etc/profile.d/*.sh; do
29          if [ -x $i ]; then
30              . $i
31          fi
32      done
33    fi
34 fi
35
36 unset loginsh

Comment line 23 and add line 25.

  • Press ESC
  • Type the colon ":"
  • Type wq

The next time you login your prompt will look like this:

For root: ~#
For users: ~$

No comments:

Post a Comment

Popular Posts