20

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.

2 Answers 2

20

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

Sign up to request clarification or add additional context in comments.

2 Comments

Acccha, I thought it had something to do with that but I tried make | less 2>& 1. Had the redirect in the wrong place.
Could you please briefly explain what 2>&1 and |& do?
14

Error output is sent to a slightly different place which isn't caught by normal pipelines, since you often want to see errors but not have them intermixed with data you're going to process further. For things like this you use a redirection:

$ make 2>&1 | less

In bash and zsh (and csh/tcsh, which is where they borrowed it from) this can be shortened to

$ make |& less

With things like make which are prone to produce lots of errors I will want to inspect later, I generally capture the output to a file and then less that file later:

$ make |& tee make.log
$ less make.log

2 Comments

I tried using make |& less in bash, but I got a syntax error.
Hrm, looks like older bash doesn't have it; the system bash (3.2) on OSX doesn't accept it but a bash 4 from MacPorts does and so does the standard bash on Maverick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.