Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Comments on How do I find out the version of a program in a terminal?

Parent

How do I find out the version of a program in a terminal?

+4
−0

How can I print the version of a program in the terminal, so that I know which one I have installed?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

OS? (2 comments)
Post
+5
−1

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.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

2 comment threads

Apt doesn't have a "query"? (10 comments)
Or, without xargs... (1 comment)
Apt doesn't have a "query"?
matthewsnyder‭ wrote 6 months ago

The two answers I was expecting to this were what Monica said, and "whatever is your distro's version of pacman -Q pkgname".

I don't have a Debian handy to test, but does dpkg/apt really not have a "show installed package info" switch like pacman? I was surprised that you had to pipe 4 steps together to print what version is installed.

alx‭ wrote 6 months ago · edited 6 months ago

Yes, but normally you don't know the name of the package. You usually know the name of the binary. That's why I started with which 'binary'. In this example, the package of neomutt is also called neomutt. But see this other example, with mbsync(1), which is packaged in isync:

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
alx‭ wrote 6 months ago · edited 6 months ago

You can directly query with the package name: dpkg -l isync, but you'd have to know the name of the package. The pipe is there for getting it from the name of the program.

which mbsync tells you 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.

matthewsnyder‭ wrote 6 months ago · edited 6 months ago

Ah, I see - so figuring out the package name is what makes it complicated. Good point! So this is actually a 3 step process:

  • Figure out full path of the command
  • Figure out what package owns it
  • Figure out the version of the package
trichoplax‭ wrote 6 months ago

Would it be helpful to future readers to replace the example in the answer with this example that makes immediately clear what the extra steps are for?

matthewsnyder‭ wrote 6 months ago

I think it would be.

alx‭ wrote 5 months ago

I have added a clarification that this is a 3-step process, quoting matthewsnyder‭. Is it good now?

trichoplax‭ wrote 5 months ago

I like the extra explanation steps. I suspect it would be easier for a future reader to match up those steps with the example if the mbsync example was used in the answer instead of the neomutt example (in the same way that it helped me understand in this comment thread).

alx‭ wrote 5 months ago

Hmm, I think so. Can you check now?

trichoplax‭ wrote 5 months ago

Yes I find that much easier to follow.