# All About My bash #

In CategoryLinux
Bysreekanth

I am not a linux guru ! . But  in my work ,  I do say hello  at least once everyday  to my Linux servers  from bash .

Bash is a unix/linux command shell to execute commands . You can find different command shells like tcsh,sh,zsh,bash in bin directoryetc., .  But my favourite&default command shell on our servers is ‘BASH‘ .

Controlling bash seems interesting to me .

Typing the command history will display all the commands used previously on the system.

I exported commands to a file this way..

[root@c6 ~]# history > history.txt

you will find a file called  .bashrc in each user’s  home directory .

 I edited my .bashrc file 

[root@cf /]# vi ~/.bashrc

and added below lines

export HISTSIZE=10000                          ( history will remember 10000 commands) 

export HISTCONTROL=erasedups       ( this will erase duplicated commands and keep only one copy of each comamnd )

shopt -s histappend                                     (this line says that commands not to be overwritten but appended) 

Ok.. alright.. , Now what If  I dont like to save the command history ? .I will just use one of the methods below.

method 1#

To clear bash history when i am on terminal  , i use the command history -c 

[root@cf /]# history -c

This will clear entire bash history whereas history -r command will clear the current session history only. 

[root@cf /]# history -r

method 2#

clear bash history when logout the session

edit .bash_logout   file which we can find in every user home directory.

[root@cf ~]# vi ~/.bash_logout    press i  to insert below lines in vim editor

 >~/.bash_history

sync;

press escape and  type  :wq   and press enter  to save the changes in vim editor.

This method will not  clear the history if you close the window without logging out from the terminal by using the command logout

method 3 #

The command  ln -sf /dev/null ~/.bash_history  will tell bash to send  history of commands to null, so it will not remember any commands that are typed in.

 [root@cf ~]# ln -sf /dev/null ~/.bash_history 

And finally .. one thing I passionate about is ,receiving  bashhistory to my mail automatically . I will write it in my next post .

Tags: , , , , , ,

Leave a Reply