There's probably more ways to do this (including checking for the actual man files (just thought of that)), but I wanted man pages for all the executables in a package a little while ago. This is what I did:
dpkg -L package-name | awk -F / '/^\/usr\/bin\// { print $4 }' | xargs -n 1 man
If you have wajig installed you can use this:
wajig listfiles package-name | awk -F / '/^\/usr\/bin\// { print $4 }' | xargs -n 1 man
Both of these show off a couple of (I think) neat little tricks.
The first is the awk command. I've just started to use awk exensively. It's starting to replace grep and egrep in a lot of my pipelines. I'm also learning to use sed some.
Anyway, the trick, obvious to any halfway proficient awk user, is the -F option. It sets the field separator. In this case, each line from dpkg or wajig is a path, so I'm using a slash (/
) as a the field separator. No biggie.
The second trick is the use of xargs. I have been putting everything in a for
loop in cases like this. However, the other day I realized that xargs can simplify things. In this case the -n 1 parameter tells xargs to only send one parameter at a time to the called command. So, man is executed once for every line passing through awk, with that line as the only parameter.
I used the xargs trick the other day to move files to destinations specified in a file, with source and destination on the same line, separated by spaces. The file looked like:
source1 dest1 source2 dest2 source3 dest3
It was generated automatically but then edited by hand. I know there are tools available for this (the moreutils package includes vidir, for instance) but I didn't have one available. So, I ran the following command on the above file:
cat movelist | xargs -n 2 mv
Quick and simple, and got the job done.
Tags: tip