55

Suppose I have a Terminal open that contains thousands of lines of output from my previous commands over the past few hours/days. How do I search that recorded output for a string? I'm especially interested in a solution that doesn't require the mouse.

I know I should have used tee, but that's not always convenient.

I know I could "Select All", then open an editor, paste, then search, but I'm hoping for something simpler (and Select All seems to require the mouse).

I was hoping there would be a "Find..." command in the menu bar (like Mac OS X has).

Jo Jo
  • 651
  • 2
    I didn't even realize there was a "Find..." command until you mentioned it in OS X, so +1 to this question for being the answer to my Googling. – ArtOfWarfare Oct 02 '13 at 17:48

7 Answers7

73

If you are running a gnome-terminal (default GUI terminal on ubuntu) you can hit shift+ctrl+f, type your search terms, and hit enter. Still graphical, but no mouse required.

underrun
  • 831
  • 1
  • 5
  • 4
  • Thanks SynapticUnderrun, but your tip doesn't seem to work for me. I'm using a fresh install of ubuntu 10.4. –  Jun 28 '11 at 20:59
  • 1
    This works on ubuntu 10.10 and 11.04. I'm running 10.10 right now and using gnome-terminal 2.32.0 so perhaps upgrading gnome-terminal would help. Since this uses a gtk pop-up window to enter in search text, you will have to be running X for it to work. But you don't need to use the mouse and it will search the entire terminal buffer (which you can set to unlimited in the Edit->Profile Preferences dialog). –  Jun 29 '11 at 16:31
  • Thanks SynapticUnderrun, I'll definitely look for that next time I can upgrade. –  Jun 29 '11 at 20:38
  • 1
    Just worked for me also in xfce4-terminal, (X)ubuntu Raring 13.04. Thanks. – Gringo Suave Oct 26 '13 at 02:25
  • works for http://konsole.kde.org – JoachimR May 09 '14 at 12:09
  • 8
    This should be the accepted answer. Works for me on Ubuntu 14.04 LTS. – user171453 Mar 16 '16 at 10:34
19

Finding text in scrollback is a weakness of most terminal emulators; the only ones I know of that provide it are OS X Terminal and Terminator. That said, you could run GNU screen in any terminal and search its scrollback buffer in copy mode.

geekosaur
  • 11,851
  • 34
  • 41
  • Thanks geekosaur. I also just found this 'idea' on the ubuntu site, which just seems to confirm that it is impossible as of yet: http://brainstorm.ubuntu.com/idea/9841/ –  Jun 28 '11 at 04:56
  • Just adding that you can use Byobu which based on TMux or Screen – Boynux Nov 27 '13 at 02:12
  • Terminator doesn't highlight text when you search for it. – user171453 Mar 16 '16 at 10:30
  • Do you happen to recall how to find text in the OS X Terminal? I'm trying to do that right now, and I'm having difficulty successfully searching out this information. – M. Justin Mar 30 '21 at 16:16
15

Shortcut to find string inside the terminal data : ctrl + shift + f

Ganesh
  • 151
4

Have you considered using pipe and grep?

YourCommand | grep str

Hope this helps

  • 5
    He asked for searching in output of already run commands and also mentioned that tee is not always convenient to use and so is grep! – Aamir Jun 29 '11 at 01:56
  • 1
    This question came up when i googled 'search terminal output' and I think this answer is great, it really helped me out (even if it technically wasn't suitable for OP) – Toms Code Jul 06 '21 at 18:25
  • This will not work for awk | grep bugs need to use awk --help | grep bugs instead. – Philip Rego Jul 13 '22 at 21:11
1

If you are using terminal on Mac OS, you can simply use Command ⌘ F

Meera Datey
  • 111
  • 2
1

Try konsole in kde. It works with gnome/unity too. Program the Find shortcut to alt-f or ctrl-f, it can search forward or backward, plus it will highlight new output that matched the searching pattern.

0

For the logs: also guake supports searching via ctrl+shift+f since https://github.com/Guake/guake/pull/1533 was merged