What is the interrupt key for Linux command "less"

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.


Solution 1:

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?

Solution 2:

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

Solution 3:

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

Solution 4:

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.