Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: search Command History

  1. #1
    Join Date
    Sep 2007
    Beans
    208

    search Command History

    How do I search command history, besides using the up and down arrows?

    For example I used a command that started with m, but I don't remember what that command was. I could up or down arrow thru several thousand commands until I recognize it.

    Is it possible search command history at a particular date?

  2. #2
    Join Date
    Oct 2006
    Beans
    58,286

    Re: search Command History

    Would you believe by using the history command ?

    Code:
    man history

  3. #3
    Join Date
    Jan 2008
    Location
    Manchester UK
    Beans
    13,573
    Distro
    Ubuntu

    Re: search Command History

    Hit Ctrl-R and start typing to search your bash history.

  4. #4
    Join Date
    Apr 2011
    Location
    Mystletainn Kick!
    Beans
    13,614
    Distro
    Ubuntu

    Re: search Command History

    It's stored in the .bash_history file in your home folder.
    Running history will show you everything listed in that file.
    Splat Double Splat Triple Splat
    Earn Your Keep
    Don't mind me, I'm only passing through.
    Once in a blue moon, I'm actually helpful
    .

  5. #5
    Join Date
    Jun 2007
    Beans
    17,337

    Re: search Command History

    You can also just use a .inputrc file either globally or locally in your home folder.
    (i'm a single user so just add to home folder.

    Code:
    gedit .inputrc
    For searches based on letter(s) typed in terminal using the page up/down keys
    Code:
    "\e[5~": history-search-backward
    "\e[6~": history-search-forward
    if wanting to use the arrow up/down instead for All searches (with nothing typed searches as usual - last command > back/foward, with something typed uses that instead

    Code:
    "\e[A": history-search-backward
    "\e[B": history-search-forward

  6. #6
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: search Command History

    Quote Originally Posted by borgward View Post
    For example I used a command that started with m, but I don't remember what that command was.
    In bash
    Code:
    fc -l m m

  7. #7
    Join Date
    Oct 2008
    Beans
    3,509

    Re: search Command History

    Same as mc4man's tip except to say the setting to bind "page up" and "page down" to search the history
    already exists in the system wide /etc/inputrc file.
    Just need to uncomment.

    ie
    Code:
    gksudo gedit /etc/inputrc
    and uncomment lines 41 and 42 to look like...
    Code:
    # alternate mappings for "page up" and "page down" to search the history
    "\e[5~": history-search-backward
    "\e[6~": history-search-forward

  8. #8
    Join Date
    Sep 2007
    Beans
    208

    Re: search Command History

    Quote Originally Posted by nothingspecial View Post
    Hit Ctrl-R and start typing to search your bash history.
    $ Ctrl Shift R (you did mean capitol R?)
    (reverse-i-search)`': m
    (reverse-i-search)`m': cat .bash_history | more

    I am looking for a way to search history for commands starting with m

  9. #9
    Join Date
    Sep 2007
    Beans
    208

    Re: search Command History

    Quote Originally Posted by schragge View Post
    In bash
    Code:
    fc -l m m
    That is only getting me one instance of the letter m. I want to see all the commands in history that start with m.

  10. #10
    Join Date
    Oct 2008
    Beans
    3,509

    Re: search Command History

    Quote Originally Posted by borgward View Post
    $ Ctrl Shift R (you did mean capitol R?)
    (reverse-i-search)`': m
    (reverse-i-search)`m': cat .bash_history | more

    I am looking for a way to search history for commands starting with m
    mc4man's solution does what you want.
    eg bind pgeup/down to
    Code:
    "\e[5~": history-search-backward
    "\e[6~": history-search-forward
    Enter one ore more characters for the start of the command then
    press pageup to cycle back through your history for commands you've used
    starting with those characters.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •