1

When I run gcc -v I'd like to output the results to a text file.

I thought something like gcc -v > ~/defaultGCC.txt would store the version output but it does not.

I also tried gcc -v | tee ~/defaultGCC.txt | more

And that didn't work...

The following:

gcc -v | tee ~/defaultGCC.txt | >
gcc -v | tee ~/defaultGCC.txt | >>

both throw errors

  • Have you tried gcc -v 2> ~/defaultGCC.txt? – Stephen Rauch Mar 30 '17 at 16:49
  • gcc: error: 2: No such file or directory – Anton Rasmussen Mar 30 '17 at 16:53
  • No space between the 2 and the >? That command should pipe stderr to the file. – Stephen Rauch Mar 30 '17 at 16:55
  • Oops, just noticed that. Ah ha!! Thank YOU!! That worked. So, my guess is that 2 means the second argument? gcc would be the first, -v is the 2nd? – Anton Rasmussen Mar 30 '17 at 16:58
  • 1
    2 means filehandle #2 which is stderr. 1 is stdout. 0 is stdin – Stephen Rauch Mar 30 '17 at 16:58
1

gcc -v is not responsible for version infomation, but rather programs which are invoked by the compiler while gcc --version is responsible for displaying gcc's version to standard output. If this is what you want, then gcc --version | tee ~/defaultGCC.txt will work. However, if the output of gcc -v is what you actually want, then gcc -v &> ~/defaultGCC.txt will give you exactly what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.