I am running an application with command $ grails run-app which prints log in terminal like below.


What I want is search a particular text (say user authorities) in this log so that I can verify further. One way using Logging Apis to write in text file but I want to search it in a terminal at the moment.

I found similar question at how to make search a text on the terminal directly which suggests screen command, but I have no idea how screen works in this case. I tried $ screen grails run-app but couldn't move ahead.

I can see screen lists with

prayag@prayag:~/zlab/nioc2egdelonk$ screen -list
There is a screen on:
    8076.pts-2.prayag   (10/06/2013 12:13:25 PM)    (Attached)
1 Socket in /var/run/screen/S-prayag.

If you use Konsole (KDE terminal emulator), you can use Ctrl + Shift + F. This might work also in other (Linux) terminal emulators; it has been confirmed to work in GNOME Terminal, the Xfce terminal, Alacritty, and Terminator.

  • @Augustin where did you find such shortcut?
    – Rodrigo
    Apr 26 '21 at 12:55
  • @Rodrigo: See the Konsole Handbook: docs.kde.org/stable5/en/konsole/konsole/…. Alternatively, if you have Konsole on your machine, have a look in the Edit menu – the keyboard shortcut should be listed next to the Find... entry.
    – Augustin
    Apr 28 '21 at 9:46
  • Working for Mobaxterm[Windows] ... Thanks mate Nov 16 '21 at 12:12

Ctrl+a (default screen command prefix), [ (enter copy mode) followed by ?SEARCH_TEXT seems to work. Press n to go to the next occurrence. From there, you can copy words, lines, regions, etc to dump into files or paste later on (with Ctrl+a, ]).

enter image description here

  • 5
    I cannot do this. So you need to press 3 keys at once? ctrl, a, [?
    – Capaj
    Mar 17 '15 at 10:13
  • 45
    use shift+ctrl+f
    – Ja8zyjits
    Jun 3 '16 at 13:25
  • @Ja8zyjits where did you find such shortcut?
    – Rodrigo
    Apr 26 '21 at 12:55
  • @Rodrigo check terminator. I should have made this an answer. Oh, i didnt have enough karma to post answer back then.
    – Ja8zyjits
    Apr 26 '21 at 14:55

You can use grep after the grails command: grails run-app | grep "user authorities". However, you will have to re-run your command.

  • 3
    This answer shouldn't be voted down, its absolutely correct.
    – amrx
    Jun 1 '15 at 2:22
  • 6
    While correct, it's more useful to have something one can do after the output has already been printed.
    – Ludwik
    Sep 27 '16 at 13:13
  • 3
    @Baron I'm even pretty sure that the asker meant to imply that the command is already running, so this doesn't answer the question.
    – Nobody
    Jan 5 '18 at 21:44

Redirect output of your command to vim-editor: grails run-app | vim -

Several tips for search using Vim:

  • type / then enter your search string user authorities
  • type :set hlsearch to highlight search results
  • type n to search forward or Shift+n to search backward
  • remember you're in editor now, so if you did some changes accidentally you can revert, just press ESC once to exit edit-mode, then press u to undo one edit
  • type :q! to exit Vim and discard your search results
  • you can do whatever you want :-D http://vim.wikia.com/wiki/Vim_Tips_Wiki

Redirect the output to pipe and send it to a grep command:

grails run-app | grep user authorities

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.