DISCLAIMER : Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility.If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.


Execute a command without saving it in the history

Prepending one or more spaces to your command won't be saved in history.
It i very useful for hiding your commands which consists of passwords on the commandline.
This is tested in bash shell and works successfully.

Example :
$ echo this goes to history
this goes to history

$ echo this wont go to history
this wont go to history

$ history
1 echo this goes to history
2 history

The manual page of "bash" shows as follows:
 
 HISTCONTROL
         A  colon-separated  list of values controlling how commands are
         saved on the history list.  If  the  list  of  values  includes
         ignorespace,  lines  which begin with a space character are not
         saved in the history list.  A value of ignoredups causes  lines
         matching  the  previous history entry to not be saved.  A value
         of ignoreboth is shorthand for ignorespace and  ignoredups.   A
         value  of erasedups causes all previous lines matching the cur
         rent line to be removed from the history list before that  line
         is  saved.   Any  value  not  in the above list is ignored.  If
         HISTCONTROL is unset, or does not include a  valid  value,  all
         lines  read  by the shell parser are saved on the history list,
         subject to the value of HISTIGNORE.  The second and  subsequent
         lines  of a multi-line compound command are not tested, and are
         added to the history regardless of the value of HISTCONTROL. 
Exit without saving history

kill -9 $$

this exits bash without saving the history. unlike explicitly disabling the history in some way, this works anywhere, and it works if you decide *after* issuing the command you don't want logged, that you don't want it logged

... $ ( or ${$} ) is the pid of the current bash instance

this also works perfectly in shells that don't have $ if you do something like

kill -9 `readlink /proc/self`
 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.