Sunday, April 28, 2024
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 1333  / 3 Years ago, fri, october 1, 2021, 5:14:07

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?


More From » command-line

 Answers
5

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

[#27243] Saturday, October 2, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
earxcept

Total Points: 310
Total Questions: 115
Total Answers: 111

Location: Japan
Member since Sat, Oct 2, 2021
3 Years ago
;