Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipe compiler output into head

Tags:

bash

I want to view only the top lines of the compiler output from gcc so I tried the command gcc myfile.c | head -10 but I still see all of the output. I use the Bash shell. Thanks.

like image 347
Michael LeVan Avatar asked Apr 17 '15 07:04

Michael LeVan


People also ask

How do you pipe the output to a file?

To redirect the output of a command to a file, type the command, specify the > or the >> operator, and then provide the path to a file you want to the output redirected to. For example, the ls command lists the files and folders in the current directory.

How do you pipe the output of a command to a file in 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.

How do you send the output of one command into the input of another command in Linux?

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.


1 Answers

Pipeline normally only redirects stdout, but compiler errors are outputed to stderr. You can redirect both stdout and stderr by using |& instead of |.

like image 172
user4098326 Avatar answered Oct 12 '22 19:10

user4098326