How can I get such a list from command line, including the version of each utility? Are they by default in the same file by any chance?

up vote 5 down vote accepted

They're [probably] all the same (gold has an extra version -- see the end of this post).
But consider the rest of this answer code-golf for the best way to extract the versions.

dpkg -L binutils | grep "/usr/bin/" | xargs -i sh -c "{} --version"

Does pretty much what roadmr's does.

dpkg -L binutils | xargs -i sh -c "{} --version 2>/dev/null || exit 0"

Tries to run everything dpkg -L ... outputs. Obviously only the executables will run so we just need to redirect error (and make xargs ignore them).

dpkg -L binutils | xargs -i bash -c '[[ -x "{}" && -f "{}" ]] && {} --version'

Test that we're dealing with an executable file rather than filtering path.


sudo apt-get install parallel
dpkg -L binutils | grep /usr/bin/ | parallel {} --version
dpkg -L binutils | parallel {} --version 2>/dev/null
dpkg -L binutils | parallel '[[ -x "{}" && -f "{}" ]] && {} --version'

This time we use GNU parallel to do the same approaches. parallel lets us skip over certain inconveniences in xargs (like it not being able to skip over any non-zero exit code. man parallel is a genuinely good read.


With all that said, while shorter, all my examples fork out into a new shell (unavoidable with xargs, and sort of the point of parallel) so they're all somewhat slower than roadmr's. The first is the quickest.

Edit: Until now...

sh <(dpkg -L binutils | awk '/bin\// {print $0 " --version"}')

Only two forks (sort of) and it's as fast as the for loop (while much shorter).


Edit: They're actually not quite the same. gold has a secondary version (1.11) which the other commands don't.

$ sh <(dpkg -L binutils | awk '/bin\// {print $0 " --version"}') | \
    grep Binutils | sort -u | column -t
GNU  addr2line  (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  ar         (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  assembler  (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  c++filt    (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  dwp        (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  elfedit    (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  gold       (GNU  Binutils  for  Ubuntu   2.23.52.20130913)  1.11
GNU  gprof      (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  ld         (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  nm         (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  objcopy    (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  objdump    (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  ranlib     (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  readelf    (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  size       (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  strings    (GNU  Binutils  for  Ubuntu)  2.23.52.20130913
GNU  strip      (GNU  Binutils  for  Ubuntu)  2.23.52.20130913

Try this:

for util in `dpkg --listfiles binutils |grep "\/usr\/bin\/"`; do
    echo -n "$util -> "; echo "" | $util --version
done

This gets all the binaries in the binutils packages and queries each one with its --version parameter. I echo an empty string for those that expect input in the terminal.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.