Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I know that uname -a shows the full machine name and details, etc. But I did uname gcc to see what the version of gcc I am running, and it returned Linux - What does that mean?

Ubuntu86: $ uname gcc
Linux

This is the machine I am on (I know it is old):

Ubuntu86: $ uname -a
Linux ubuntu86 2.6.8.1-3-386 #1 Tue Oct 12 12:41:57 BST 2004 i686 GNU/Linux

How can I check the version of gcc running on this machine?

I installed it by typing:

Ubuntu86: $ sudo apt-get install gcc

So I know it has installed a version of gcc, but no idea what version.

share|improve this question
2  
Generally speaking: You shouldn't be passing random parameters to programs. It's harmless in the case of uname, but it can easily cause programs to perform operations you really don't want to do. Check the man page of the command in question to see what parameters it accepts and what they mean. (Many also do something reasonably safe when invoked with simply the name of the binary with no parameters.) –  Michael Kjörling Nov 27 '13 at 13:24
    
Thanks @MichaelKjörling, I have been working a lot in SCO, so I forgot about all this with the man pages and the -v option. I will keep that in mind for the future :) –  Kevdog777 Nov 27 '13 at 13:28

4 Answers 4

up vote 5 down vote accepted

And for the first question: uname, when passed no option, is equivalent to uname -s thus displays Linux on your system.

The gcc argument passed is not an option (doesn't start with an hyphen) so is simply ignored by the command.

share|improve this answer
    
So you saying, whatever follows uname needs to start with a hyphen, in order for it to work properly? –  Kevdog777 Nov 27 '13 at 9:32
    
Try uname --help or man uname for list of available options. –  SF. Nov 27 '13 at 9:33
2  
It already works properly. This command only expect options and ignore anything else. This is unusual. Many commands report unexpected parameters with a warning or an error. –  jlliagre Nov 27 '13 at 9:34

uname shows the name of the OS you're working on - it just ignored the argument and did its usual work. It does not display versions of installed software.

Most commands - including gcc support --version argument, so gcc --version displays your current GCC version.

share|improve this answer
    
Ok, that is a bit simpler than gcc -v, thanks. –  Kevdog777 Nov 27 '13 at 9:29

For the second question the answer is: gcc -v
On the last line of the print out you can find the version of gcc installed on your system.

share|improve this answer
    
Great, thanks. It is showing: gcc version 3.3.4 (Debian 1:3.3.4-9ubuntu5) - why Debian? Or is that just the version? –  Kevdog777 Nov 27 '13 at 9:27
1  
Welcome! Because Ubuntu is actually a Debian based distro. –  coffeMug Nov 27 '13 at 9:28

On Debian-based systems, including Ubuntu, you can find out the installation status as well as the possibly installed version of a package (if you know the package name) using dpkg -l (that's ell, not I or one). Doing so generally does not require root access, as it is a read-only operation.

To find out which package owns a specific file, use dpkg -S. Again, this does not require root access.

Putting the two together, you get something like:

$ dpkg -S $(which gcc)
gcc: /usr/bin/gcc
$ dpkg -l gcc
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name              Version       Architecture  Description
+++-=================-=============-=============-=======================================
ii  gcc               4:4.7.2-1     amd64         GNU C compiler
$

which tells me that on my particular system, package version 4:4.7.2-1 of the gcc package for the amd64 architecture is fully installed and configured (ii status).

If you want a single command, it would be dpkg -l $(dpkg -S $(which gcc) | awk -F: '{print $1}') which will show the same output as the dpkg -l gcc command example above. Here I use awk to split the data on : and return the first portion of the output.

Note that the package version does not necessarily exactly reflect the version that the program itself reports. In my case, gcc --version says it is gcc (Debian 4.7.2-5) 4.7.2 which for all practical purposes is "close enough", but it may make a difference if you are trying to figure out of a behavior you are seeing is a bug or not.

Even more generally, you shouldn't be passing random parameters to programs and expecting things to work (for some definition of "work"). In the specific case of uname, it's harmless, but it can easily cause programs to perform operations you really don't want to do; some even potentially dangerous. Check the man page of the command in question to see what parameters it accepts and what they mean. (Many also do something reasonably safe when invoked with simply the name of the binary with no parameters. Lots of console applications will display version and copyright information when launched with no parameters, though there are many that do things differently.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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