How do I find out the version of a program in a terminal?
How can I print the version of a program in the terminal, so that I know which one I have installed?
3 answers
On Debian, the package manager can tell the versions of the installed software.
Let's say we want to know the version of mbsync(1).
Quoting a comment by @matthewsnyder, this is a 3 step process:
- Figure out full path of the command
- Figure out what package owns it
- Figure out the version of the package
The 3 steps are shown below:
alx@debian:~$ which mbsync
/usr/bin/mbsync
alx@debian:~$ which mbsync | xargs dpkg -S
isync: /usr/bin/mbsync
alx@debian:~$ which mbsync | xargs dpkg -S | cut -f1 -d:
isync
alx@debian:~$ which mbsync | xargs dpkg -S | cut -f1 -d: | xargs dpkg -l
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 isync 1.4.4-5+b1 amd64 IMAP and MailDir mailbox synchronizer
Let's explain the steps:
which mbsync
tells the full path of the binary.
... | xargs dpkg -S
(i.e., dpkg -S /usr/bin/mbsync
) tells you the package that provides the file.
... | cut -f1 -d:
extracts the package name alone.
... | xargs dpkg -l
(i.e., dpkg -l isync
) tells you the info about the isync package.
However, if you didn't install the program with the package manager, obviously this won't help.
Other package managers for other OSes will have similar features.
Many programs have a --version
option, so that's the first thing I try when I need to find this out. If that doesn't work, --help
usually produces a full list of options, so if version info is provided in a non-standard way, that should lead you to it. (Some programs support -v
for version, but it's possible that's instead mapped to something else, as pointed out in a comment, so be careful.)
Unfortunately, not all applications provide this information. I don't know if you can get it from the OS.
If the program was installed with your package manager, the package manager should be able to tell you that. For example:
$ pacman --query bash
bash 5.2.026-2
If you don't know the package name, you need to first figure out the full path of your command, for example:
$ which mbsync
/usr/bin/mbsync
With this you can ask the package manager what package owns that file. For example:
$ pacman --query --owns /usr/bin/mbsync
/usr/bin/mbsync is owned by isync 1.4.4-4
Pacman is nice enough that it already tells me the version, but if it didn't, I would now do pacman --query isync
to get it.
1 comment thread