Skip to main content
Mention that dpkg -S is dpkg-query too.
Source Link
Stephen Kitt
  • 481k
  • 59
  • 1.2k
  • 1.4k

If you are on a Debian based distribution, you can use the package manager to figure it out:

$ dpkg -S '*bin/man'
man-db: /usr/bin/man

This tells us man-db is the package which owns /usr/bin/man.

$ dpkg -l man-db
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  man-db         2.10.2-1     amd64        tools for reading manual pages

Then we ask what version of man-db is installed. This is man-db's upstream version 2.10.2 released by the distribution with an extra -1. The -1 represents a patch done by the distribution. This may just include build-rules, but could also include fixes to 2.10.2 ported from later versions.

dpkg-query can be used to extract the version:

$ dpkg-query -W -f '${Version}\n' man-db
2.10.2-1

Putting all this together:

$ dpkg-query -W -f '${Version}\n' $(dpkg -S '*bin/man' | cut -d: -f1)
2.10.2-1

Or a function which could go into .bashrc:

ver() {
  package=$(dpkg -S "*bin/$1" | cut -d: -f1)
  version=$(dpkg-query -W -f '${Version}' "$package")
  printf "%s\n" "$version"
}

ver man
2.10.2-1

(Behind the scenes, dpkg -S is really dpkg-query -S, but dpkg-query -S can't be combined with -W -f.)

If you are on a Debian based distribution, you can use the package manager to figure it out:

$ dpkg -S '*bin/man'
man-db: /usr/bin/man

This tells us man-db is the package which owns /usr/bin/man.

$ dpkg -l man-db
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  man-db         2.10.2-1     amd64        tools for reading manual pages

Then we ask what version of man-db is installed. This is man-db's upstream version 2.10.2 released by the distribution with an extra -1. The -1 represents a patch done by the distribution. This may just include build-rules, but could also include fixes to 2.10.2 ported from later versions.

dpkg-query can be used to extract the version:

$ dpkg-query -W -f '${Version}\n' man-db
2.10.2-1

Putting all this together:

$ dpkg-query -W -f '${Version}\n' $(dpkg -S '*bin/man' | cut -d: -f1)
2.10.2-1

Or a function which could go into .bashrc:

ver() {
  package=$(dpkg -S "*bin/$1" | cut -d: -f1)
  version=$(dpkg-query -W -f '${Version}' "$package")
  printf "%s\n" "$version"
}

ver man
2.10.2-1

If you are on a Debian based distribution, you can use the package manager to figure it out:

$ dpkg -S '*bin/man'
man-db: /usr/bin/man

This tells us man-db is the package which owns /usr/bin/man.

$ dpkg -l man-db
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  man-db         2.10.2-1     amd64        tools for reading manual pages

Then we ask what version of man-db is installed. This is man-db's upstream version 2.10.2 released by the distribution with an extra -1. The -1 represents a patch done by the distribution. This may just include build-rules, but could also include fixes to 2.10.2 ported from later versions.

dpkg-query can be used to extract the version:

$ dpkg-query -W -f '${Version}\n' man-db
2.10.2-1

Putting all this together:

$ dpkg-query -W -f '${Version}\n' $(dpkg -S '*bin/man' | cut -d: -f1)
2.10.2-1

Or a function which could go into .bashrc:

ver() {
  package=$(dpkg -S "*bin/$1" | cut -d: -f1)
  version=$(dpkg-query -W -f '${Version}' "$package")
  printf "%s\n" "$version"
}

ver man
2.10.2-1

(Behind the scenes, dpkg -S is really dpkg-query -S, but dpkg-query -S can't be combined with -W -f.)

No need for which. dpkg-query avoids all the post-processing.
Source Link
Stephen Kitt
  • 481k
  • 59
  • 1.2k
  • 1.4k

If you are on a debianDebian based distrobutiondistribution, you can use the package manager to figure it out:

$ dpkg -S $(which man)'*bin/man'
man-db: /usr/bin/man

This tells us man-db is the package which owns /usr/bin/man.

$ dpkg -l man-db
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  man-db         2.10.2-1     amd64        tools for reading manual pages

Then we ask what version of man-db is installed. This is man-db's upstream version 2.10.2 released by the distribution with an extra -1. The -1 represents a patch done by the distribution. This may just include build-rules, but could also include fixes to 2.10.2 ported from later versions.

If you want a 1-liner, you could put it all togeatherdpkg-query can be used to extract the version:

dpkg$ dpkg-lquery $(dpkg-W -Sf $(which'${Version}\n' man)-db
2.10.2-1

Putting all this together:

$ |dpkg-query sed-W 's/:.*$//'-f )'${Version}\n' |$(dpkg grep-S ^ii'*bin/man' | awk '{ printcut $3-d: }'-f1)
2.10.2-1

Or a function which could go into .bashrc:

ver() {
  binary=$(which "$1")
  package=$(dpkg -S "$binary""*bin/$1" | sedcut 's/-d:.*$//' -f1)
  version=$(dpkg -l "$package" | grep ^iiquery |-W awk-f ''${ print $3 Version}' "$package")
  printf "%s\n" "$version"
}

ver man
2.10.2-1

If you are on a debian based distrobution, you can use the package manager to figure it out:

$ dpkg -S $(which man)
man-db: /usr/bin/man

This tells us man-db is the package which owns /usr/bin/man.

$ dpkg -l man-db
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  man-db         2.10.2-1     amd64        tools for reading manual pages

Then we ask what version of man-db is installed. This is man-db's upstream version 2.10.2 released by the distribution with an extra -1. The -1 represents a patch done by the distribution. This may just include build-rules, but could also include fixes to 2.10.2 ported from later versions.

If you want a 1-liner, you could put it all togeather:

dpkg -l $(dpkg -S $(which man) | sed 's/:.*$//' ) | grep ^ii | awk '{ print $3 }'
2.10.2-1

Or a function which could go into .bashrc:

ver() {
  binary=$(which "$1")
  package=$(dpkg -S "$binary" | sed 's/:.*$//')
  version=$(dpkg -l "$package" | grep ^ii | awk '{ print $3 }')
  printf "%s\n" "$version"
}

ver man
2.10.2-1

If you are on a Debian based distribution, you can use the package manager to figure it out:

$ dpkg -S '*bin/man'
man-db: /usr/bin/man

This tells us man-db is the package which owns /usr/bin/man.

$ dpkg -l man-db
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  man-db         2.10.2-1     amd64        tools for reading manual pages

Then we ask what version of man-db is installed. This is man-db's upstream version 2.10.2 released by the distribution with an extra -1. The -1 represents a patch done by the distribution. This may just include build-rules, but could also include fixes to 2.10.2 ported from later versions.

dpkg-query can be used to extract the version:

$ dpkg-query -W -f '${Version}\n' man-db
2.10.2-1

Putting all this together:

$ dpkg-query -W -f '${Version}\n' $(dpkg -S '*bin/man' | cut -d: -f1)
2.10.2-1

Or a function which could go into .bashrc:

ver() {
  package=$(dpkg -S "*bin/$1" | cut -d: -f1)
  version=$(dpkg-query -W -f '${Version}' "$package")
  printf "%s\n" "$version"
}

ver man
2.10.2-1
debugged
Source Link
Kamil Maciorowski
  • 24.5k
  • 2
  • 69
  • 129

If you are on a debian based distrobution, you can use the package manager to figure it out:

$ dpkg -S $(which man)
man-db: /usr/bin/man

This tells us man-db is the package which owns /usr/bin/man.

$ dpkg -l man-db
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  man-db         2.10.2-1     amd64        tools for reading manual pages

Then we ask what version of man-db is installed. This is man-db's upstream version 2.10.2 released by the distribution with an extra -1. The -1 represents a patch done by the distribution. This may just include build-rules, but could also include fixes to 2.10.2 ported from later versions.

If you want a 1-liner, you could put it all togeather:

dpkg -l $(dpkg -S $(which man) | sed 's/:.*$//' ) | grep ^ii | awk '{ print $3 }'
2.10.2-1

Or a function which could go into .bashrc:

ver() {
  binary=$(which $1"$1")
  package=$(dpkg -S "$binary" | sed 's/:.*$//')
  version=$(dpkg -l "$package") | grep ^ii | awk '{ print $3 }')
  printf "%s\n" "$version"
}

ver man
2.10.2-1

If you are on a debian based distrobution, you can use the package manager to figure it out:

$ dpkg -S $(which man)
man-db: /usr/bin/man

This tells us man-db is the package which owns /usr/bin/man.

$ dpkg -l man-db
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  man-db         2.10.2-1     amd64        tools for reading manual pages

Then we ask what version of man-db is installed. This is man-db's upstream version 2.10.2 released by the distribution with an extra -1. The -1 represents a patch done by the distribution. This may just include build-rules, but could also include fixes to 2.10.2 ported from later versions.

If you want a 1-liner, you could put it all togeather:

dpkg -l $(dpkg -S $(which man) | sed 's/:.*$//' ) | grep ^ii | awk '{ print $3 }'
2.10.2-1

Or a function which could go into .bashrc:

ver() {
  binary=$(which $1)
  package=$(dpkg -S "$binary" | sed 's/:.*$//')
  version=$(dpkg -l "$package") | grep ^ii | awk '{ print $3 }'
  printf "%s\n" "$version"
}

ver man
2.10.2-1

If you are on a debian based distrobution, you can use the package manager to figure it out:

$ dpkg -S $(which man)
man-db: /usr/bin/man

This tells us man-db is the package which owns /usr/bin/man.

$ dpkg -l man-db
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  man-db         2.10.2-1     amd64        tools for reading manual pages

Then we ask what version of man-db is installed. This is man-db's upstream version 2.10.2 released by the distribution with an extra -1. The -1 represents a patch done by the distribution. This may just include build-rules, but could also include fixes to 2.10.2 ported from later versions.

If you want a 1-liner, you could put it all togeather:

dpkg -l $(dpkg -S $(which man) | sed 's/:.*$//' ) | grep ^ii | awk '{ print $3 }'
2.10.2-1

Or a function which could go into .bashrc:

ver() {
  binary=$(which "$1")
  package=$(dpkg -S "$binary" | sed 's/:.*$//')
  version=$(dpkg -l "$package" | grep ^ii | awk '{ print $3 }')
  printf "%s\n" "$version"
}

ver man
2.10.2-1
added 342 characters in body
Source Link
Stewart
  • 16k
  • 5
  • 48
  • 101
Loading
Source Link
Stewart
  • 16k
  • 5
  • 48
  • 101
Loading