Draw kernel module dependancy graph.

lsmod | perl -e 'print "digraph \"lsmod\" {";<>;while(<>){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"\n" for split/,/,$_[3]}print "}"' | dot -Tpng | display -
parse `lsmod' output and pass to `dot' drawing utility then finally pass it to an image viewer

35
By: bandie91
2011-11-27 14:02:35

1 Alternatives + Submit Alt

What Others Think

Wonderful.
kaedenn · 745 weeks ago
"Imagemagick is smarter than you think. It can display dot files, so the dot command is unnecessary." - Comment by dratini0 8 hours ago
bandie91 · 744 weeks and 6 days ago
So how would you do this with ImageMagick?
SuperFly · 744 weeks and 6 days ago
SuperFly: lsmod | perl -e 'print "digraph \"lsmod\" {";;while(){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"\n" for split/,/,$_[3]}print "}"' | display - you can also replace 'display - ' with 'gm display - ' if you have GraphicsMagick installed instead of ImageMagick (or just install graphicsmagick-imagemagick-compat to replace GraphicsMagick completely)
psykotron · 744 weeks and 6 days ago
@SuperFly: with IM not the whole procedure, just the `dot | display' thing. `display' can interpret this format too and displays it on transparent (for me). @psykotron: i think reboot unneccessary. Run `fc-cache -r' !
bandie91 · 744 weeks and 5 days ago
I have ImageMagick-6.2.8.0-4.el5_5.3.x86_64 installed and I get this: lsmod | perl -e 'print "digraph \"lsmod\" {";<>;while(<>){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"\n" for split/,/,$_[3]}print "}"' | display - display: no decode delegate for this image format `/tmp/magick-XX6QuBzg'.
SuperFly · 744 weeks and 5 days ago
# `awk` is very good at parsing the output of `lsmod` lsmod | awk 'BEGIN{print "digraph lsmod {"}; NR!=1&&NF==4{printf("\t%s -> { %s };\n", $1, gensub(",", "", "g", $4))}; END{print "}"}' | dot -Tpng | display -
kev · 744 weeks and 5 days ago
# sorry, please change `gensub(",", "", "g", $4)` to `gensub(",", " ", "g", $4)`
kev · 744 weeks and 5 days ago
@unixmonkey21861: it not really works... how modulenames in 4th field filled? printf doesnt accept gensub's array.
bandie91 · 744 weeks and 5 days ago
brilliant..
alperyilmaz · 744 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: