Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Piping program output to less does not display beginning of the output

Tags:

unix

pipe

I am trying to make a bunch of files in my directory, but the files are generating ~200 lines of errors, so they fly past my terminal screen too quickly and I have to scroll up to read them.

I'd like to pipe the output that displays on the screen to a pager that will let me read the errors starting at the beginning. But when I try

make | less

less does not display the beginning of the output - it displays the end of the output that's usually piped to the screen, and then tells me the output is 1 line long. When I try typing Gg, the only line on the screen is the line of the makefile that executed, and the regular screen output disappears.

Am I using less incorrectly? I haven't really ever used it before, and I'm having similar problems with something like, sh myscript.sh | less where it doesn't immediately display the beginning of the output file.

like image 680
Kevin Burke Avatar asked Apr 03 '11 01:04

Kevin Burke


People also ask

How to pipe to less in Linux?

Now you can hit ctrl + c and only less will receive it, letting you use less on a pipe just like you would on a log-file or other growing file.

How to pipe output to a file Linux?

In Linux, for redirecting output to a file, utilize the ”>” and ”>>” redirection operators or the top command. Redirection allows you to save or redirect the output of a command in another file on your system. You can use it to save the outputs and use them later for different purposes.

What character is used to pipe data from the output of one program to the input of another?

You can make it do so by using the pipe character '|'. Pipe is used to combine two or more commands, and in this, the output of one command acts as input to another command, and this command's output may act as input to the next command and so on.

How do you pipe a command output?

The > symbol is used to redirect output by taking the output from the command on the left and passing as input to the file on the right.


1 Answers

The errors from make appear on the standard error stream (stderr in C), which is not redirected by normal pipes. If you want to have it redirected to less as well, you need either make |& less (csh, etc.) or make 2>&1 | less (sh, bash, etc.).

like image 71
Jeremiah Willcock Avatar answered Feb 07 '23 03:02

Jeremiah Willcock