How to check command version on Linux

When working with various Linux commands, you may be wondering what version of the command you are using. Of course, the version relates to the binary executable file itself, and traditionally is maintained by the system package manager, which is responsible for checking on updated versions and installing them at the user’s discretion. Commands in Linux typically undergo slow, subtle changes. Some commands have not changed much at all since the 70s, when they were introduced on Unix. Others have new versions developed regularly, and you need to check your version to know which features it has. In this tutorial, you will learn how to check the version of a command on a Linux system.

In this tutorial you will learn:

  • How to check command version with options and package manager
How to check command version on Linux
How to check command version on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to check command version on Linux




There are numerous possible ways for us to check the version of a command in Linux. Not all methods will work, since some commands are programmed differently. Typically, though, Linux commands follow conventional and even unwritten standards that make them pretty uniform across the board, so it is almost certain that one of the methods below will yield you the version number you are looking for. Check out the various methods below:

  1. The typical way to check for the version of a command in Linux is by appending the --version option.
    $ ls --version
    ls (GNU coreutils) 8.32
    
    $ java --version
    openjdk 19.0.2 2023-01-17
    
  2. If the first method did not work, some developers like to use the option -V instead, or just as an alternative and in addition to the aforementioned command option.
    $ python3 -V
    Python 3.10.6
    
  3. We can also use the system package manager to check the installed version of a command. For example, using apt on a Debian based system:
    $ apt show dos2unix
    Package: dos2unix
    Version: 7.4.2-2
    
    NOTE
    In the above example, the command name dos2unux matched the package name. But frequently this is not the case. For example, the ls command is part of the coreutils package, so we would need to check the version number of that package.
  4. Using the package manager dnf on a Red Hat or Fedora based Linux distribution:
    $ dnf info dos2unix
    Name         : dos2unix
    Version      : 7.4.3
    

Closing Thoughts




In this tutorial, we saw how to check the command version on a Linux system. This allows us to determine what version of a Linux command is installed on our system. With this information, we can figure out if our command is up to date or not, and what set of features it has. For security announcements and audits, it also allows us to make sure that our installed versions are not affected by the latest exploits.