37

When you do shift-f with less, you can see the file update in real time, and you get the "Waiting for data...(interrupt to abort)" message.

The updating works fine, but what is the interrupt? nothing seems to work (Ctrl-C, Esc, Ctrl-I etc). I always have to kill the terminal which is a pain.

studiohack
  • 13,468
  • 19
  • 88
  • 118

6 Answers6

33

Ctrl+C works for me. When I use the F command in less, it says "(interrupt to abort)". The "interrupt" that it's referring to is whatever key is bound to the terminal interrupt. The command stty -a shows the relevant terminal settings:

speed 38400 baud; rows 50; columns 80; line = 0; intr = ^C; quit = ^; erase = ^H; kill = ^U; eof = ^D; eol = ; eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

It's the intr = ^C that shows that interrupt is generated by Ctrl+C.

If you do stty -a what does it show?

Audwin Oyong
  • 117
  • 1
  • 1
  • 6
Randy Orrison
  • 7,371
  • 2
  • 28
  • 25
  • 1
    it says intr = ^C. Aha!! it's actually Ctrl-shift-c - ie upper case. Thanks for the help –  Oct 25 '09 at 13:05
  • 4
    That's weird - I've never known Ctrl+Shift to be different from just Ctrl. Mine shows upper case C, but Ctrl+c (without shift) works fine. – Randy Orrison Oct 25 '09 at 13:21
  • 5
    I've never used a system that treated ctrl-c and ctrl-C differently, either. Just a data point. – CarlF Oct 25 '09 at 13:45
  • 1
    I'm having the same issue, and neither ctrl-c nor ctrl-shift-c works. Could this have something to do with the fact that i'm running less inside a screen session? – jenming Dec 13 '13 at 22:35
  • 2
    This works for me: 'ctrl-shift-c' switch to normal mode and simply enter `q` to quit – Mohammad Ali Akbari Mar 30 '15 at 20:00
4

Ctrl + C did not work for me. However, I was able to stop the process with q.

Carsten
  • 141
  • 3
2

As @RandyOrrison mentioned, ^C (control + c) is the appropriate interrupt character. Although, how less responds to this signal will vary based on the options provided at execution time.

Normally, an interrupt character causes less to stop whatever it is doing and return to its command prompt (i.e. not the terminal/tty prompt).

If instead, you want to signal less to quit and return to the terminal/tty prompt, you should use the -K or --quit-on-intr option. This will cause less to exit immediately (with status 2) when an interrupt character (usually ^C) is typed.

less manpage

-K , --quit-on-intr

Causes less to exit immediately (with status 2) when an interrupt character (usually ^C) is typed. Normally, an interrupt character causes less to stop whatever it is doing and return to its command prompt. Note that use of this option makes it impossible to return to the command prompt from the "F" command.

less -K [filename]...
less --quit-on-intr [filename]...
Travis Clarke
  • 181
  • 1
  • 5
2

ctrl-C is closing the process at the head of the pipe, not signeling less, when using a pipeline like this.

head-process | less

I got it to work with:

less -f <(head-process)

There may be a better way.

ctrl-alt-delor
  • 2,326
  • 19
  • 29
  • AFAIK the signal should get to `less` as well; "not signalling `less`" is somewhat surprising to me. About the solution: [yeah](https://superuser.com/a/1547677/432690). :) – Kamil Maciorowski Aug 13 '21 at 22:04
-1

Try Shift + Ctrl + C, I had the same issue and needed to do Ctrl + Z -> fg -> Q to quit.

  • There is no need to put `less` into background and resuming it with `fg`, before quitting. You could have pressed `q` right away. – dirdi Sep 27 '19 at 12:43
  • @dirdi When less is under the control of journalctl and F has been typed so the prompt "Waiting for data... (interrupt to abort)" is displaying, CTRL+C exits the journalctl process instead and 'q' is ignored as well. So in the above scenario, CTRL + Z > fg seems to work i.e. journalctl is still running and it displaying in less at the end of the file so I can now scroll up from the bottom in less. hjeaninn, thanks for this answer, I upvoted this answer because it solved my problem with journalctl. – buzz3791 Aug 31 '22 at 15:43
-2

I was stuck in less with no argument over than the file I wanted to fast check from my terminal, Ctrl-c, Ctrl shift-c nothing worked. Ctrl-z did the job :)

  • 3
    ^Z does not kill or quit `less` but stops and puts it into background for being resumed later. Therefore, this is not an answer to the question. – dirdi Sep 27 '19 at 12:41