Search text in command output on a PuTTY terminal

121,189

Solution 1

The Ctrl + a + [ is meant for use within the application screen (an app for multiplexing consoles).

less

Generally the easiest method to do this is to use tools such as less and to pipe the output from whatever application is generating the messages on the console, and search within the application less. You can do so using the forward slash (/) followed by whatever string you're searching for. Hit return to execute the search.

Example

$ less filename.log

...then in less, type a forward slash followed by string to search, foo

grep

In the same vain as above with using less, you can also use tools such as tail to print the lats few lines of a applications log file messages, and also use grep to search for only lines that contain a matching string/pattern.

$ grep "somestring" filename.log

Solution 2

You can also right click the title bar at the top of the window and select Copy All to Clipboard, then paste into a text editor and use that to search.

Share:
121,189

Related videos on Youtube

Ashwin
Author by

Ashwin

Updated on September 18, 2022

Comments

  • Ashwin
    Ashwin over 1 year

    I would like to know how to search particular text on the terminal. If I do cat of log files, I would like to find certain words like job or summary so that I don't have to read through the entire log file.

    I know there have been a similar post about this. The answer from that post is Ctrl + A + [ <text> which doesn't seem to work for me. When I press that I get a message No bracket in top line (press Return) or If I press those keys together I get the message ESC.

    It there a way to do this with PuTTY? Alternatively, is there a generic way to search for text in the output of commands?

    • Jeff Hewitt
      Jeff Hewitt over 10 years
      It helps if you tell us which terminal emulator you're using.
    • slm
      slm over 10 years
      What are the commands you're looking to search output from? Just general commands or is there a log file that a server/service is writing messages to that you want to search through?
    • jordanm
      jordanm over 10 years
      konsole supports this with ctrl+shift+f
  • Ashwin
    Ashwin over 10 years
    I didnt quite get it. After I do cat filename.log | less how can I find particular text from the whole screen, if at all its possible.
  • Ashwin
    Ashwin over 10 years
    Cool this is what I was looking for. I can find it by executing cat filename.log | grep Summary or less filename
  • slm
    slm over 10 years
    @Ashwin - glad it worked for you, see my updates, for shorter versions of using both tools so you can skip having to use cat.
  • Mahender Reddy Yasa
    Mahender Reddy Yasa about 6 years
    how to search for next number 2 search item(for ex second "error" in file)
  • slm
    slm about 6 years
    @MahenderY - if you have follow up questions please ask them on the main site and reference this Q&A within them.