[colug-432] Search Command History

Tim Randles tim.randles at gmail.com
Tue Feb 11 15:57:40 EST 2014


One aspect of history that I find useful is timestamps.  On Red Hat-based
distros (CentOS, fedora, RHEL, SLC...) bash history timestamps are disabled
by default.  I can't speak for other shells and distros.  To enable them
export the environment variable HISTTIMEFORMAT in your .bash_profile.

export HISTTIMEFORMAT="%F %T "
produces output like:

[tcr at case ~]# history | tail -3
 1003  2014-02-11 13:51:17 cat .bash_profile
 1004  2014-02-11 13:54:38 pwd
 1005  2014-02-11 13:54:40 history | tail -3




On Tue, Feb 11, 2014 at 1:48 PM, Jim Wildman <jim at rossberry.com> wrote:

> Sure, if what you want is in the last few commands, and you just want to
> repeat that command.  But say you need to redo the command, but change
> it slightly and it was 5 days ago?  And note that I used the word
> efficient.  ditto for use of vi or any other editor.  There are better
> ways than uparrow, backspace, etc.
>
> And for the case of unreliable vpn...use screen on your destination,
> along with the other tips.
>
> Really my point is that there are MANY efficiency tools built into the
> *nix command line.  If you spend any time at all administering systems,
> and especially if you get paid to do it, it pays to know them.  If
> nothing else, it will put you miles ahead of the arrow key guys in the
> productivity department.
>
> On Tue, 11 Feb 2014, Steve VanSlyck wrote:
>
>
>> It's easier to press one arrow key a few times than to type out a command
>> phrase.
>>
>>
>>
>> Jim Wildman <jim at rossberry.com> wrote:
>>
>> With bash
>> !?phrase
>> will search for and execute that last command containg phrase
>> history | grep apt (as others said) will find the command, with the
>> command number in front
>> !number will execute that command
>> !number:s/oldphrase/newphrase/  will edit and then execute the command
>> you can do similar things with the 'fc' command which will open your
>> default editor with the given command. The command executes when you
>> exit the editor.
>>    983  exit
>>    984  ls
>>    985  ls
>>    986  cd rossdev
>>    987  ls
>>    988  cat rbhosts.txt
>>    989  svn up
>>    990  exit
>>    991  scdr
>>    992  pine
>>    993  screen
>>    994  scdr
>>    995  scdr
>>    996  scdr
>>    997  exit
>>    998  scdr
>>    999  exit
>>   1000  scdr
>>   1001  man fc
>>   1002  history 20
>> fc 988
>> opens vi with "cat rbhosts.txt" in the buffer
>> When I
>> see someone who only uses the arrow keys, I know they have not
>> gotten serious about efficient command line use.
>>  csh (sorry, no idea off the top of my head).
>>
>>  Alternately, if you need a reason to use zsh, here's one more:  you can
>> typ
>> e
>>  'apt' and then use the up arrow to reverse through full commands in your
>>  history that start with "apt".
>>
>>
>>
>>
>> ____________________________________________________________
>> ________________
>> Jim Wildman, CISSP, RHCE       jim at rossberry.com http://www.rossberry.net
>> "Society in every state is a blessing, but Government, even in its best
>> state, is a necessary evil; in its worst state, an intolerable one."
>> Thomas Paine
>>
>> ____________________________________________________________
>> ________________
>> colug-432 mailing list
>> colug-432 at colug.net
>> http://lists.colug.net/mailman/listinfo/colug-432
>>
>>
>> --
>> Sent from Kaiten Mail. Please excuse my brevity.
>>
>>
> ----------------------------------------------------------------------
> Jim Wildman, CISSP, RHCE       jim at rossberry.com http://www.rossberry.net
> "Society in every state is a blessing, but Government, even in its best
> state, is a necessary evil; in its worst state, an intolerable one."
> Thomas Paine
> _______________________________________________
> colug-432 mailing list
> colug-432 at colug.net
> http://lists.colug.net/mailman/listinfo/colug-432
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.colug.net/pipermail/colug-432/attachments/20140211/bcc68771/attachment.html 


More information about the colug-432 mailing list