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

Thread: search Command History

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Beans
    185

    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
    Location
    Ayrshire
    Beans
    40,417
    Distro
    Ubuntu Development Release

    Re: search Command History

    Would you believe by using the history command ?

    Code:
    man history

  3. #3
    Join Date
    Apr 2011
    Location
    Mystletainn Kick!
    Beans
    4,933
    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
    .

  4. #4
    Join Date
    Jun 2007
    Beans
    13,622

    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

  5. #5
    Join Date
    Jan 2008
    Location
    Manchester UK
    Beans
    13,634
    Distro
    Ubuntu

    Re: search Command History

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

  6. #6
    Join Date
    Sep 2007
    Beans
    185

    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

  7. #7
    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.

  8. #8
    Join Date
    Sep 2007
    Beans
    185

    Re: search Command History

    Quote Originally Posted by stinkeye View Post
    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.
    13:58:24 abc@1520: ~$ "\e[5~": history-search-backward
    \e[5~:: command not found
    13:59:08 tom@1520: ~$
    13:59:14 abc@1520: ~$ "\m[5~": history-search-backward
    \m[5~:: command not found
    13:59:31 abc@1520: ~$ "\e[5~":m history-search-backward
    \e[5~:m: command not found

    Can you run the command on your machine and show me the results? What version are you running?

  9. #9
    Rebelli0us is offline Extra Foam Sugar Free Ubuntu
    Join Date
    Feb 2008
    Beans
    722

    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

    Reverse search still eludes me, not sure it's possible in Linux, but I'm used to it from using 4NT.

    Here is my complete .inputrc with Command History Recall and in-place Filename Completion

  10. #10
    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

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
  •