{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# The Unix Shell: Getting Help" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Use a search engine\n", "\n", "This is often the simplest approach." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Getting general information" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/usr/share/info/bash.info\n", "File: bash.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)\n", "\n", "Bash Features\n", "*************\n", "\n", "This text is a brief description of the features that are present in\n", "the Bash shell (version 3.2, 28 September 2006).\n", "\n", " This is Edition 3.2, last updated 28 September 2006, of `The GNU\n", "Bash Reference Manual', for `Bash', Version 3.2.\n", "\n", " Bash contains features that appear in other popular shells, and some\n", "features that only appear in Bash. Some of the shells that Bash has\n", "borrowed concepts from are the Bourne Shell (`sh'), the Korn Shell\n", "(`ksh'), and the C-shell (`csh' and its successor, `tcsh'). The\n", "following menu breaks the features up into categories based upon which\n", "one of these other shells inspired the feature.\n", "\n", " This manual is meant as a brief introduction to features found in\n", "Bash. The Bash manual page should be used as the definitive reference\n", "on shell behavior.\n", "\n", "* Menu:\n", "\n", "* Introduction::\t\tAn introduction to the shell.\n", "* Definitions::\t\t\tSome definitions used in the rest of this\n", "\t\t\t\tmanual.\n", "* Basic Shell Features::\tThe shell \"building blocks\".\n", "* Shell Builtin Commands::\tCommands that are a part of the shell.\n", "* Shell Variables::\t\tVariables used or set by Bash.\n", "* Bash Features::\t\tFeatures found only in Bash.\n", "* Job Control::\t\t\tWhat job control is and how Bash allows you\n", "\t\t\t\tto use it.\n", "* Using History Interactively::\tCommand History Expansion\n", "* Command Line Editing::\tChapter describing the command line\n", "\t\t\t\tediting features.\n", "* Installing Bash::\t\tHow to build and install Bash on your system.\n", "* Reporting Bugs::\t\tHow to report bugs in Bash.\n", "* Major Differences From The Bourne Shell::\tA terse list of the differences\n" ] } ], "source": [ "info bash | head -n 40" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Command shell commands" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)\n", "These shell commands are defined internally. Type `help' to see this list.\n", "Type `help name' to find out more about the function `name'.\n", "Use `info bash' to find out more about the shell in general.\n", "Use `man -k' or `info' to find out more about commands not in this list.\n", "\n", "A star (*) next to a name means that the command is disabled.\n", "\n", " JOB_SPEC [&] (( expression ))\n", " . filename [arguments] :\n", " [ arg... ] [[ expression ]]\n", " alias [-p] [name[=value] ... ] bg [job_spec ...]\n", " bind [-lpvsPVS] [-m keymap] [-f fi break [n]\n", " builtin [shell-builtin [arg ...]] caller [EXPR]\n", " case WORD in [PATTERN [| PATTERN]. cd [-L|-P] [dir]\n", " command [-pVv] command [arg ...] compgen [-abcdefgjksuv] [-o option\n", " complete [-abcdefgjksuv] [-pr] [-o continue [n]\n", " declare [-afFirtx] [-p] [name[=val dirs [-clpv] [+N] [-N]\n", " disown [-h] [-ar] [jobspec ...] echo [-neE] [arg ...]\n", " enable [-pnds] [-a] [-f filename] eval [arg ...]\n", " exec [-cl] [-a name] file [redirec exit [n]\n", " export [-nf] [name[=value] ...] or false\n", " fc [-e ename] [-nlr] [first] [last fg [job_spec]\n", " for NAME [in WORDS ... ;] do COMMA for (( exp1; exp2; exp3 )); do COM\n", " function NAME { COMMANDS ; } or NA getopts optstring name [arg]\n", " hash [-lr] [-p pathname] [-dt] [na help [-s] [pattern ...]\n", " history [-c] [-d offset] [n] or hi if COMMANDS; then COMMANDS; [ elif\n", " jobs [-lnprs] [jobspec ...] or job kill [-s sigspec | -n signum | -si\n", " let arg [arg ...] local name[=value] ...\n", " logout popd [+N | -N] [-n]\n", " printf [-v var] format [arguments] pushd [dir | +N | -N] [-n]\n", " pwd [-LP] read [-ers] [-u fd] [-t timeout] [\n", " readonly [-af] [name[=value] ...] return [n]\n", " select NAME [in WORDS ... ;] do CO set [--abefhkmnptuvxBCHP] [-o opti\n", " shift [n] shopt [-pqsu] [-o long-option] opt\n", " source filename [arguments] suspend [-f]\n", " test [expr] time [-p] PIPELINE\n", " times trap [-lp] [arg signal_spec ...]\n", " true type [-afptP] name [name ...]\n", " typeset [-afFirtx] [-p] name[=valu ulimit [-SHacdfilmnpqstuvx] [limit\n", " umask [-p] [-S] [mode] unalias [-a] name [name ...]\n", " unset [-f] [-v] [name ...] until COMMANDS; do COMMANDS; done\n", " variables - Some variable names an wait [n]\n", " while COMMANDS; do COMMANDS; done { COMMANDS ; }\n" ] } ], "source": [ "help" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Using the Unix manual\n", "\n", "Most commands have built-in help accessible with `-h` or `--help`. Let's see how to use the `man` command." ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "man, version 1.6c\n", "\n", "usage: man [-adfhktwW] [section] [-M path] [-P pager] [-S list]\n", "\t[-m system] [-p string] name ...\n", "\n", " a : find all matching entries\n", " c : do not use cat file\n", " d : print gobs of debugging information\n", " D : as for -d, but also display the pages\n", " f : same as whatis(1)\n", " h : print this help message\n", " k : same as apropos(1)\n", " K : search for a string in all pages\n", " t : use troff to format pages for printing\n", " w : print location of man page(s) that would be displayed\n", " (if no name given: print directories that would be searched)\n", " W : as for -w, but display filenames only\n", "\n", " C file : use `file' as configuration file\n", " M path : set search path for manual pages to `path'\n", " P pager : use program `pager' to display pages\n", " S list : colon separated section list\n", " m system : search for alternate system's man pages\n", " p string : string tells which preprocessors to run\n", " e - [n]eqn(1) p - pic(1) t - tbl(1)\n", " g - grap(1) r - refer(1) v - vgrind(1)\n" ] }, { "ename": "", "evalue": "1", "output_type": "error", "traceback": [] } ], "source": [ "man -h" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "man, version 1.6c\n", "\n", "usage: man [-adfhktwW] [section] [-M path] [-P pager] [-S list]\n", "\t[-m system] [-p string] name ...\n", "\n", " a : find all matching entries\n", " c : do not use cat file\n", " d : print gobs of debugging information\n", " D : as for -d, but also display the pages\n", " f : same as whatis(1)\n", " h : print this help message\n", " k : same as apropos(1)\n", " K : search for a string in all pages\n", " t : use troff to format pages for printing\n", " w : print location of man page(s) that would be displayed\n", " (if no name given: print directories that would be searched)\n", " W : as for -w, but display filenames only\n", "\n", " C file : use `file' as configuration file\n", " M path : set search path for manual pages to `path'\n", " P pager : use program `pager' to display pages\n", " S list : colon separated section list\n", " m system : search for alternate system's man pages\n", " p string : string tells which preprocessors to run\n", " e - [n]eqn(1) p - pic(1) t - tbl(1)\n", " g - grap(1) r - refer(1) v - vgrind(1)\n" ] }, { "ename": "", "evalue": "1", "output_type": "error", "traceback": [] } ], "source": [ "man --help" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### What does the manual say about itself?" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "man(1) man(1)\n", "\n", "\n", "\n", "NAME\n", " man - format and display the on-line manual pages\n", "\n", "SYNOPSIS\n", " man [-acdfFhkKtwW] [--path] [-m system] [-p string] [-C config_file]\n", " [-M pathlist] [-P pager] [-B browser] [-H htmlpager] [-S section_list]\n", " [section] name ...\n", "\n", "\n", "DESCRIPTION\n", " man formats and displays the on-line manual pages. If you specify sec-\n", " tion, man only looks in that section of the manual. name is normally\n", " the name of the manual page, which is typically the name of a command,\n", " function, or file. However, if name contains a slash (/) then man\n", " interprets it as a file specification, so that you can do man ./foo.5\n", " or even man /cd/foo/bar.1.gz.\n" ] } ], "source": [ "man man | head -n 20" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### What does the parenthesis in `man (1)` mean?\n", "\n", "The text in parenthesis indicates the section of the Unix manual (`man`) to find out more about the keyword. The standard sections are:\n", "\n", "1. General commands\n", "2. System calls\n", "3. C library functions\n", "4. Special files (usually devices, those found in /dev) and drivers\n", "5. File formats and conventions\n", "6. Games and screensavers\n", "7. Miscellanea\n", "8. System administration commands and daemons\n", "\n", "Full details in [Unix Programmer's Mnaual](http://plan9.bell-labs.com/7thEdMan/v7vol1.pdf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### We can use `man` to look up information related to fish" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "blowfish(3ssl), BF_set_key(3ssl), BF_encrypt(3ssl), BF_decrypt(3ssl), BF_ecb_encrypt(3ssl), BF_cbc_encrypt(3ssl), BF_cfb64_encrypt(3ssl), BF_ofb64_encrypt(3ssl), BF_options(3ssl) - Blowfish encryption\n", "blowfish(n) - Implementation of the Blowfish block cipher\n" ] } ], "source": [ "man -k \"fish\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is the same as the `apropos` command" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "blowfish(3ssl), BF_set_key(3ssl), BF_encrypt(3ssl), BF_decrypt(3ssl), BF_ecb_encrypt(3ssl), BF_cbc_encrypt(3ssl), BF_cfb64_encrypt(3ssl), BF_ofb64_encrypt(3ssl), BF_options(3ssl) - Blowfish encryption\n", "blowfish(n) - Implementation of the Blowfish block cipher\n" ] } ], "source": [ "apropos \"fish\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Getting brief descriptions" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "fc-cat(1) - read font information cache files\n", "parcat(1) - cat files or fifos in parallel\n", "cat(1) - concatenate and print files\n" ] } ], "source": [ "man -f cat" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is the same as the `whatis` command" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "fc-cat(1) - read font information cache files\n", "parcat(1) - cat files or fifos in parallel\n", "cat(1) - concatenate and print files\n" ] } ], "source": [ "whatis cat" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Getting the manual entry for `cat`" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "CAT(1) BSD General Commands Manual CAT(1)\n", "\n", "NAME\n", " cat -- concatenate and print files\n", "\n", "SYNOPSIS\n", " cat [-benstuv] [file ...]\n", "\n", "DESCRIPTION\n", " The cat utility reads files sequentially, writing them to the standard\n", " output. The file operands are processed in command-line order. If file\n", " is a single dash (`-') or absent, cat reads from the standard input. If\n", " file is a UNIX domain socket, cat connects to it and then reads it until\n", " EOF. This complements the UNIX domain binding capability available in\n", " inetd(8).\n", "\n", " The options are as follows:\n", "\n", " -b Number the non-blank output lines, starting at 1.\n" ] } ], "source": [ "man cat | head -n 20" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### RTFM\n", "\n", "On help sites, you will often be asked to Read The F(ine) Manual if you ask a question that is answered by `man`." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "blowfish(3) OpenSSL blowfish(3)\n", "\n", "\n", "\n", "NAME\n", " blowfish, BF_set_key, BF_encrypt, BF_decrypt, BF_ecb_encrypt,\n", " BF_cbc_encrypt, BF_cfb64_encrypt, BF_ofb64_encrypt, BF_options -\n", " Blowfish encryption\n", "\n", "SYNOPSIS\n", " #include \n", "\n", " void BF_set_key(BF_KEY *key, int len, const unsigned char *data);\n", "\n", " void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,\n", " BF_KEY *key, int enc);\n", " void BF_cbc_encrypt(const unsigned char *in, unsigned char *out,\n", " long length, BF_KEY *schedule, unsigned char *ivec, int enc);\n", " void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out,\n", " long length, BF_KEY *schedule, unsigned char *ivec, int *num,\n" ] } ], "source": [ "man 3ssl blowfish | head -n 20" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "blowfish(n) Blowfish Block Cipher blowfish(n)\n", "\n", "\n", "\n", "______________________________________________________________________________\n", "\n", "NAME\n", " blowfish - Implementation of the Blowfish block cipher\n", "\n", "SYNOPSIS\n", " package require Tcl 8.4\n", "\n", " package require blowfish ?1.0.4?\n", "\n", " ::blowfish::blowfish ?-mode [ecb|cbc]? ?-dir [encrypt|decrypt]? -key\n", " keydata ?-iv vector? ?-out channel? ?-chunksize size? ?-pad padchar? [\n", " -in channel | ?--? data ]\n", "\n", " ::blowfish::Init mode keydata iv\n", "\n" ] } ], "source": [ "man n blowfish | head -n 20" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Bash", "language": "bash", "name": "bash" }, "language_info": { "codemirror_mode": "shell", "file_extension": ".sh", "mimetype": "text/x-sh", "name": "bash" } }, "nbformat": 4, "nbformat_minor": 2 }