Skip to content

Comment on 2013 Resolutions: a man page a day makes the newb go away

Comments

How will you know which man page to read "next"?

So far the plan is to start with "man" and then go through the man pages of my most commonly used commands: cd, ls, grep, cat, sed, etc.

After that, I may write a little shell script that simply opens one at random for me.

May I suggest:

* Read your primary shell's manpage.

* Read alternative shell's manpages. Most particularly zsh, if you're not already using it.

* Look at your bash history and most frequently used commands. Read those manpages.

* Read manpages of language(s) you're looking to develop in.

* Read manpages for tools that are supplanting existing tools. E.g.: ip(8) vs. ifconfig(8).

* Read manpages for not just commands (1 & 8) but file formats (section 5), special files (4), and system and library calls (2 & 3).

* Follow references in manpages (the "SEE ALSO" section(s).

* Try reversing the process. Use apropos to find tools which accomplish a given task.

* On Debian or Ubuntu, install the dwww package and surf manpages locally at http://localhost/dwww/man/ within your web browser.

Please share that script when you do it. It might be fancy to read man pages when one is bored instead of watching something as the randomness might dig some cool facts of the system for you which you did not know before hand.

Just found this little snippet via a quick Google search:

  dir="/bin"; man $(ls $dir |sed -n "$(echo $(( $RANDOM % $(ls $dir |wc -l | awk "{ print $1; }" ) + 1 )) )p")
I think I may write my own version as well. Just to gain a bit more experience with shell scripting.

Unfortunately there are a couple of commands that don't have a man page, e.g. mpplu (from argyllcms-1.4.0-2.fc17.x86_64) or showchar (from psutils-1.17-38.fc17.x86_64).

I know the OP said he was a VIM guy, but here's my first approximation to a random manual page script for emacs; it doesn't strip out directories (like man1) or specify different sections of the manual, but it indexes manual pages, so you not only won't try opening pages for commands that don't have them, but you'll get other pages too (eg, the TCL library man pages):

  ;; Taken from http://emacswiki.org/emacs/ElispCookbook#toc57
  (defun directory-dirs (dir)
    "Find all directories in DIR."
    (unless (file-directory-p dir)
      (error "Not a directory `%s'" dir))
    (let ((dir (directory-file-name dir))
          (dirs '())
          (files (directory-files dir nil nil t)))
      (dolist (file files)
        (unless (member file '("." ".."))
          (let ((file (concat dir "/" file)))
            (when (file-directory-p file)
              (setq dirs (append (cons file
                                       (directory-dirs file))
                                 dirs))))))
      dirs))

  ;; Taken from
  ;; http://stackoverflow.com/questions/3815467/stripping-duplicate-elements-in-a-list-of-strings-in-elisp
  (defun strip-duplicates (list)
    (let ((new-list nil))
      (while list
        (when (and (car list) (not (member (car list) new-list)))
          (setq new-list (cons (car list) new-list)))
        (setq list (cdr list)))
      (nreverse new-list)))

  ;; Display a random manual page
  (defun open-random-man-page ()
    (interactive)
    ;; Get manual page paths from the environment.
    (setq man-paths (parse-colon-path (getenv "MANPATH")))
    (setq man-dirs ())
    (dolist (man-path man-paths)
      (setq man-dirs (append man-dirs (directory-dirs man-path))))

    ;; Get a list of files in manual page paths.
    (setq files ())
    (dolist (man-dir man-dirs)
      (setq files (append files (directory-files man-dir nil "^[^\.].*"))))

    ;; Fixup the files to be a list of man pages.
    (setq man-pages ())
    (dolist (file files)
      (setq man-pages (cons (car (split-string file "\\." t)) man-pages)))

    (setq man-pages (strip-duplicates man-pages))

    (random t)
    (man (nth (random (length man-pages)) man-pages)))
Be aware that Emacs lisp is still something I'm learning; I'm sure the above could be improved.

Another thing to consider: on my main Debian Linux box at home, this script finds roughly 20k man pages, which would take more than fifty years to read them all if you are reading one a day. Granted, I have tons of stuff installed, you could read more than one a day, reading a random one will lead to/make you aware of what's available on your system, etc, etc. Perhaps I should write up a blog post about this whole experience . . .

cd is a shell builtin, not a command, so there is no man page for it. There will be information about it in your shell's man page, though, which should be worth reading.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.