Weekend Project - Exploring /usr/bin/ and /usr/sbin/
Have you ever wondered what all that stuff in your /usr/bin/ and /usr/sbin/ directories does?
Probably not, but I have.
True UNIX geeks will most likely scoff at me for my ignorance, but everybody has to start somewhere, right? The brute force approach to exploring those directories would have been to get a listing of every command and run man on each one individually. But that strikes me as awfully tedious and it seems like something that is just begging to be automated. So in my usual hacky manner I did.
The NAME section of a man page usually gives a nice, succinct description of what the command does. I found a shell script that would extract sections from a man page. Unfortunately, OS X does weird formatting things when you pipe man’s output to a file, so I had to pipe it through the col command as an intermediate step. I then wrapped everything up into a Python script that would iterate through all of the commands in those two directories, grab the NAME section, and finally output it to file.
This is far from a perfect solution, and I’m sure I’m missing out on some useful information or better ways of doing it. For example, error handling is managed by piping stderr away and then completely ignoring it. But it’s good enough for my casual browsing needs and it taught me a little bit about sed and some of the other tools available to me on my system.




1 month ago
