1

On a VM running Ubuntu 18.04 Visual Studio Code is installed. When code --version is executed on the command line, the follow info is outputted in the terminal:

knot22@juniper:~/Desktop/pile$ code --version
1.40.2
f359dd69833dd8800b54d458f6d37ab7c78df520
x64

Is there a command that will limit the output only to the version so just 1.40.2 is outputted?

I want just the version number, not all of the data outputted by --version for the code package.

  • Possible duplicate of How do I get the version of an application from the command line? – JoKeR Dec 3 '19 at 13:15
  • 1
    That link does not answer this question. I only want the version number, not all the other data that is being outputted. – knot22 Dec 3 '19 at 15:25
  • dpkg -s code | grep -i version this one is not working either? – JoKeR Dec 3 '19 at 20:10
  • @JoKeR That does not give the desired format. – knot22 Dec 3 '19 at 20:54
  • apt-cache show code | grep -i version should do the trick let me know. – JoKeR Dec 4 '19 at 8:48
2

You can simply use head command like that

code --version | head -1

You would get :

knot22@juniper:~/Desktop/pile$ code --version | head -1
1.40.2
knot22@juniper:~/Desktop/pile$

Little explanation :

  • head -number_lines would display the first number_lines, so in your case, it would display just the 1rst line due to -1 option (e.g -3 would display 3 lines)
| improve this answer | |
  • I wouldn't call it a proper solution as it only reads the header, as an example it won't work for vlc – JoKeR Dec 4 '19 at 8:52
  • I just do the test with vlc, I got the version number not alone like that : VLC media player 3.0.8 Vetinari (revision 3.0.8-0-gf350b6b5a7) VLC version 3.0.8 Vetinari (3.0.8-0-gf350b6b5a7) – damadam Dec 4 '19 at 9:01
  • 1
    Exactly, I written much proper check. Apt-cache should do that trick. – JoKeR Dec 4 '19 at 9:04
  • the command --version will not always show version printed – JoKeR Dec 4 '19 at 9:10
  • but probably OP didn't want to see the word version on result too, probably to get it using some code (an auto update script for example) – damadam Dec 4 '19 at 9:17
2

To check the proper information about the package you can use apt-cache command for example:

$ apt-cache show netcat

Package: netcat
Priority: optional
Section: universe/net
Installed-Size: 30
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Ruben Molina <rmolina@udea.edu.co>
Architecture: all
Version: 1.10-40
Depends: netcat-traditional (>= 1.10-39)
Filename: pool/universe/n/netcat/netcat_1.10-40_all.deb
Size: 3340
MD5sum: 37c303f02b260481fa4fc9fb8b2c1004
SHA1: 0371a3950d6967480985aa014fbb6fb898bcea3a
SHA256: eeecb4c93f03f455d2c3f57b0a1e83b54dbeced0918ae563784e86a37bcc16c9
Description-en: TCP/IP swiss army knife -- transitional package
 This is a "dummy" package that depends on lenny's default version of
 netcat, to ease upgrades. It may be safely removed.
Description-md5: 1353f8c1d079348417c2180319bdde09
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu

Just type:

apt-cache show netcat | grep -i version

Version: 1.10-40
| improve this answer | |
  • well there's official deb repository https://packages.microsoft.com/repos/ – JoKeR Dec 4 '19 at 9:17
  • you can add a sed command to avoid displaying Version:, which would be something like that : apt-cache show netcat | grep -i version | sed "s/Version: //" (even if -cache isn't really useful) – damadam Dec 5 '19 at 11:06

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.