Skip to content

Instantly share code, notes, and snippets.

@macolyte
Created December 27, 2011 20:32
Show Gist options
  • Save macolyte/1525044 to your computer and use it in GitHub Desktop.
Save macolyte/1525044 to your computer and use it in GitHub Desktop.
import os, subprocess
desc = []
c_line = "man 1 %s | col -b > /tmp/man.txt"
s_line = "cat /tmp/man.txt | sed -n -e \"/^NAME/,/^SYNOPSIS/ p\" | grep -v -e \"^[A-Z]\""
dirs = ["/usr/bin/", "/usr/sbin/"]
for dir in dirs:
    for f in os.listdir(dir):
         cmd = c_line % f
         tmp = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
         p = subprocess.Popen(s_line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         out = p.stdout.read().strip()
         desc.append(out)
good_stuff = [x for x in desc if x]
outfile = open("commands.txt", "w")
for item in good_stuff:
     print>>outfile, item
outfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment