Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

List manual pages and system commands on Mac OS X (See related posts)

bash --version
man --version

man builtin
help   # list builtin commands


alias mycmds="alias -p | /usr/bin/awk -F= '{print \$1}' | /usr/bin/sort; declare -F | /usr/bin/awk '{print \$NF }' | /usr/bin/sort"
mycmds


# For more information on Bash shortcuts see:
# - Bash Shell Shortcuts, http://linuxhelp.blogspot.com/2005/08/bash-shell-shortcuts.html
# - Bash Magic Tricks, http://gnubie.blogspot.com/2007/07/bash-magic-tricks_18.html

[TAB + TAB]   # hitting the TAB key twice will list all available commands
auto[TAB + TAB]   # list all available commands with name auto*


# cf. Terminal Productivity Tips,
# http://www.afp548.com/article.php?story=20070525141734763
#echo "set show-all-if-ambiguous on" >> ~/.inputrc    # ... then open new Terminal window ...
#[TAB]    # hitting the TAB key once will list all available commands
#auto[TAB]    # list all available commands with name auto*


export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/libexec
export IFS=$' \t\n'

# For information on MANPATH see man man, man 5 man.conf
# and the specified MANPATH directories in: 
# sudo nano +40 /usr/share/misc/man.conf or 
# sudo nano +40 /private/etc/man.conf
# (make sure there is no MANPATH directory that is a symbolic link to another directory)

function mpath() { /usr/bin/man -W | /usr/bin/tr ':' '\n'; return 0; }
function mpath() { /usr/bin/man --path | /usr/bin/tr ':' '\n'; return 0; }   # alternative
function mpath() { /usr/bin/manpath | /usr/bin/tr ':' '\n'; return 0; }   # alternative
mpath

function path() { printf "%s\n" "${PATH}" | /usr/bin/tr ':' '\n'; return 0; }
function path() { printf -- "${PATH//:/\n}\n"; return 0; }   # alternative
path


man makewhatis
man whatis
man apropos
man periodic   # cf. nano /private/etc/periodic/weekly/500.weekly

# rebuild whatis database (index of manual pages)
# cf. http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/manpages.5.html
for dir in $(mpath); do find -x "${dir}" -type f -name whatis -ls; done
nano /usr/share/man/whatis
/usr/bin/sudo /usr/libexec/makewhatis.local $(/usr/bin/man --path)
/usr/bin/sudo /usr/libexec/makewhatis -v $(/usr/bin/man -W)   # alternative


# update locate database
# for a more secure locate see: /opt/local/bin/port info slocate
man locate locate.updatedb
/usr/bin/sudo /usr/libexec/locate.updatedb


# list manual pages
unset -f lsmans
function lsmans() {

   declare sudo find xargs basename sed
   sudo=/usr/bin/sudo
   find=/usr/bin/find
   xargs=/usr/bin/xargs
   basename=/usr/bin/basename
   sed=/usr/bin/sed

   for dir in $(/usr/bin/man -W | /usr/bin/tr ':' '\n'); do 
      #$sudo $find -x "${dir}" ! -type d 2>/dev/null
      $find -x "${dir}" \( -type f -or -type l \) -print0 2>/dev/null | $xargs -0 -n 3000 $basename
      #$find -x "${dir}" \( -type f -or -type l \) -print0 2>/dev/null | $xargs -0 -n 3000 $basename | $sed 's/\.[^\.]*$//'
   done

   return 0

}


mpath

lsmans
man -aW "*"

lsmans | wc -l
man -aW "*" | wc -l

man -aW  chmod
man -aW  "*chmod*"
lsmans | egrep -i chmod
apropos chmod
whatis chmod
locate -0 *chmod* | xargs -0 basename 
 
man -aW perl | nl
man -aW "*perl*" | xargs basename | nl
lsmans | egrep -i perl | nl
apropos perl | nl
whatis perl | nl

man -aW "*roff*" | xargs basename | nl
lsmans | egrep -i roff | nl
apropos roff | awk '{print $1}' | nl
whatis roff | nl

man -aW "*64*" | xargs basename | nl
lsmans | egrep -i 64 | nl
apropos 64 | awk '{print $1}' | nl

man -aW "*ssl*" | xargs basename | nl
lsmans | egrep -i ssl | nl
apropos ssl | awk '{print $1}' | nl

man -aW "*printer*" | xargs basename | nl
lsmans | egrep -i printer | nl
apropos printer | awk '{print $1}' | nl


lsmans | egrep -i '\.gz$'
lsmans | egrep -i util
lsmans | egrep -i sql
lsmans | egrep -i dns
lsmans | egrep "^ds[^A].*"
lsmans | egrep -i ssh
lsmans | egrep -i ssl
lsmans | egrep -i secur
lsmans | egrep -i ipsec
lsmans | egrep -i darwin
lsmans | egrep -i mac
lsmans | egrep -i apple
lsmans | egrep -i osx


#------------------------------


# list commands
unset -f lscmds
function lscmds() {

   declare sudo find xargs basename
   sudo=/usr/bin/sudo
   find=/usr/bin/find
   xargs=/usr/bin/xargs
   basename=/usr/bin/basename

   for dir in $(printf -- "${@:-${PATH}}" | /usr/bin/tr ':' '\n'); do 
      #$sudo $find -x "${dir}" \( -type f -or -type l \) -perm -555 2>/dev/null
      $find -x "${dir}" \( -type f -or -type l \) -perm -555 -print0 2>/dev/null | $xargs -0 -n 1000 $basename
      #$find -x "${dir}" \( -type f -or -type l \) -perm -555 -print0 2>/dev/null | $xargs -0 -n 1000 $basename
   done

   return 0

}


path

lscmds
lscmds | wc -l

lscmds /opt | egrep -i pdf
lscmds /usr | egrep -i pdf
#lscmds /opt | xargs -n 2000 basename | egrep -i pdf
lscmds /opt:/usr | egrep -i pdf

lscmds | egrep -i pdf | nl
apropos pdf | awk '{print $1}' | nl

lscmds | egrep -i roff | nl
apropos roff | awk '{print $1}' | nl

lscmds | egrep -i util
lscmds | egrep -i roff
lscmds | egrep -i html
lscmds | egrep -i "^ds.*"
lscmds | egrep -i x11
lscmds | egrep -i secur
lscmds | egrep -i file
lscmds | egrep -i mount
lscmds | egrep -i dns
lscmds | egrep -i ssh
lscmds | egrep -i ssl
lscmds | egrep -i system
lscmds | egrep -i darwin
lscmds | egrep -i mac
lscmds | egrep -i apple
lscmds | egrep -i osx

You need to create an account or log in to post comments to this site.