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.)
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.)-v
option. I will keep that in mind for the future :)