You are previewing Linux® Command Line and Shell Scripting Bible.
O'Reilly logo
Linux® Command Line and Shell Scripting Bible

Book Description

There's a lot to be said for going back to basics. Not only does this Bible give you a quick refresher on the structure of open-source Linux software, it also shows you how to bypass the hefty graphical user interface on Linux systems and start interacting the fast and efficient way with command lines and automated scripts. You'll learn how to manage files on the filesystem, start and stop programs, use databases, even do Web programming without a GUI with this one-stop resource.

Table of Contents

  1. Copyright
  2. About the Author
  3. Credits
  4. Acknowledgments
  5. Introduction
    1. Who Should Read This Book
    2. How This Book Is Organized
    3. Conventions and Features
    4. Notes and Cautions
    5. Minimum Requirements
    6. Where to Go fromHere
  6. I. The Linux Command Line
    1. 1. Starting with Linux Shells
      1. 1.1. What Is Linux?
        1. 1.1.1. Looking into the Linux kernel
          1. 1.1.1.1. System memory management
          2. 1.1.1.2. Software program management
          3. 1.1.1.3. Hardware management
          4. 1.1.1.4. Filesystem management
        2. 1.1.2. The GNU utilities
          1. 1.1.2.1. The core GNU utilities
          2. 1.1.2.2. The shell
        3. 1.1.3. The Linux desktop environment
          1. 1.1.3.1. The X Windows system
          2. 1.1.3.2. The KDE desktop
          3. 1.1.3.3. The GNOME desktop
          4. 1.1.3.4. Other desktops
      2. 1.2. Linux Distributions
        1. 1.2.1. Core Linux distributions
        2. 1.2.2. Specialized Linux distributions
        3. 1.2.3. The Linux LiveCD
      3. 1.3. Summary
    2. 2. Getting to the Shell
      1. 2.1. Terminal Emulation
        1. 2.1.1. Graphics capabilities
          1. 2.1.1.1. Character sets
          2. 2.1.1.2. Control codes
          3. 2.1.1.3. Block mode graphics
          4. 2.1.1.4. Vector graphics
          5. 2.1.1.5. Display buffering
          6. 2.1.1.6. Color
        2. 2.1.2. The keyboard
      2. 2.2. The terminfo Database
      3. 2.3. The Linux Console
      4. 2.4. The xterm Terminal
        1. 2.4.1. Command line parameters
        2. 2.4.2. The xterm main menu
          1. 2.4.2.1. X event commands
          2. 2.4.2.2. Output capturing
          3. 2.4.2.3. Keyboard settings
        3. 2.4.3. The VT options menu
          1. 2.4.3.1. VT features
          2. 2.4.3.2. VT commands
          3. 2.4.3.3. Current screen commands
        4. 2.4.4. The VT fonts menu
          1. 2.4.4.1. Set the font
          2. 2.4.4.2. Display the font
          3. 2.4.4.3. Specify the font
      5. 2.5. The Konsole Terminal
        1. 2.5.1. Command line parameters
        2. 2.5.2. Sessions
        3. 2.5.3. The menu bar
          1. 2.5.3.1. Session
          2. 2.5.3.2. Edit
          3. 2.5.3.3. View
          4. 2.5.3.4. Bookmarks
          5. 2.5.3.5. Settings
          6. 2.5.3.6. Help
      6. 2.6. The GNOME Terminal
        1. 2.6.1. The command line parameters
        2. 2.6.2. Tabs
        3. 2.6.3. The menu bar
          1. 2.6.3.1. File
          2. 2.6.3.2. Edit
          3. 2.6.3.3. View
          4. 2.6.3.4. Terminal
          5. 2.6.3.5. Tabs
          6. 2.6.3.6. Help
      7. 2.7. Summary
    3. 3. Basic bash Shell Commands
      1. 3.1. Starting the Shell
      2. 3.2. The Shell Prompt
      3. 3.3. The bash Manual
      4. 3.4. Filesystem Navigation
        1. 3.4.1. The Linux filesystem
        2. 3.4.2. Traversing directories
          1. 3.4.2.1. Absolute filepaths
          2. 3.4.2.2. Relative filepaths
      5. 3.5. File and Directory Listing
        1. 3.5.1. Basic listing
        2. 3.5.2. Modifying the information presented
        3. 3.5.3. The complete parameter list
        4. 3.5.4. Filtering listing output
      6. 3.6. File Handling
        1. 3.6.1. Creating files
        2. 3.6.2. Copying files
        3. 3.6.3. Linking files
        4. 3.6.4. Renaming files
        5. 3.6.5. Deleting files
      7. 3.7. Directory Handling
        1. 3.7.1. Creating directories
        2. 3.7.2. Deleting directories
      8. 3.8. Viewing File Contents
        1. 3.8.1. Viewing file statistics
        2. 3.8.2. Viewing the file type
        3. 3.8.3. Viewing the whole file
          1. 3.8.3.1. The cat command
          2. 3.8.3.2. The more command
          3. 3.8.3.3. The less command
        4. 3.8.4. Viewing parts of a file
          1. 3.8.4.1. The tail command
          2. 3.8.4.2. The head command
      9. 3.9. Summary
    4. 4. More bash Shell Commands
      1. 4.1. Monitoring Programs
        1. 4.1.1. Peeking at the processes
          1. 4.1.1.1. Unix-style parameters
          2. 4.1.1.2. BSD-style parameters
          3. 4.1.1.3. The GNU long parameters
        2. 4.1.2. Real-time process monitoring
        3. 4.1.3. Stopping processes
          1. 4.1.3.1. The kill command
          2. 4.1.3.2. The killall command
      2. 4.2. Monitoring Disk Space
        1. 4.2.1. Mounting media
          1. 4.2.1.1. The mount command
          2. 4.2.1.2. The umount command
        2. 4.2.2. Using the df command
        3. 4.2.3. Using the du command
      3. 4.3. Working with Data Files
        1. 4.3.1. Sorting data
        2. 4.3.2. Searching for data
        3. 4.3.3. Compressing data
          1. 4.3.3.1. The bzip2 utility
          2. 4.3.3.2. The gzip utility
          3. 4.3.3.3. The zip utility
        4. 4.3.4. Archiving data
      4. 4.4. Summary
    5. 5. Using Linux Environment Variables
      1. 5.1. What Are Environment Variables?
        1. 5.1.1. Global environment variables
        2. 5.1.2. Local environment variables
      2. 5.2. Setting Environment Variables
        1. 5.2.1. Setting local environment variables
        2. 5.2.2. Setting global environment variables
      3. 5.3. Removing Environment Variables
      4. 5.4. Default Shell Environment Variables
      5. 5.5. Setting the PATH Environment Variable
      6. 5.6. Locating System Environment Variables
        1. 5.6.1. Login shell
          1. 5.6.1.1. The /etc/profile file
          2. 5.6.1.2. The $HOME startup files
        2. 5.6.2. Interactive shell
        3. 5.6.3. Non-interactive shell
      7. 5.7. Variable Arrays
      8. 5.8. Using Command Aliases
      9. 5.9. Summary
    6. 6. Understanding Linux File Permissions
      1. 6.1. Linux Security
        1. 6.1.1. The /etc/passwd file
        2. 6.1.2. The /etc/shadow file
        3. 6.1.3. Adding a new user
        4. 6.1.4. Removing a user
        5. 6.1.5. Modifying a user
          1. 6.1.5.1. usermod
          2. 6.1.5.2. passwd and chpasswd
          3. 6.1.5.3. chsh, chfn, and chage
      2. 6.2. Using Linux Groups
        1. 6.2.1. The /etc/group file
        2. 6.2.2. Creating new groups
        3. 6.2.3. Modifying groups
      3. 6.3. Decoding File Permissions
        1. 6.3.1. Using file permission symbols
        2. 6.3.2. Default file permissions
      4. 6.4. Changing Security Settings
        1. 6.4.1. Changing permissions
        2. 6.4.2. Changing ownership
      5. 6.5. Sharing Files
      6. 6.6. Summary
    7. 7. Working with Editors
      1. 7.1. The vim Editor
        1. 7.1.1. The basics of vim
        2. 7.1.2. Editing data
        3. 7.1.3. Copy and paste
        4. 7.1.4. Search and substitute
      2. 7.2. The emacs Editor
        1. 7.2.1. Using emacs on the console
          1. 7.2.1.1. The basics of emacs
          2. 7.2.1.2. Editing data
          3. 7.2.1.3. Copying and pasting
          4. 7.2.1.4. Searching and replacing
          5. 7.2.1.5. Using buffers in emacs
          6. 7.2.1.6. Using windows in console mode emacs
        2. 7.2.2. Using emacs in X Windows
      3. 7.3. The KDE Family of Editors
        1. 7.3.1. The KWrite editor
        2. 7.3.2. The Kate editor
      4. 7.4. The GNOME Editor
        1. 7.4.1. Starting gedit
        2. 7.4.2. Basic gedit features
        3. 7.4.3. Setting preferences
          1. 7.4.3.1. View
          2. 7.4.3.2. Editor
          3. 7.4.3.3. Font & Colors
          4. 7.4.3.4. Syntax Highlighting
          5. 7.4.3.5. Plugins
      5. 7.5. Summary
  7. II. Shell Scripting Basics
    1. 8. Basic Script Building
      1. 8.1. Using Multiple Commands
      2. 8.2. Creating a Script File
      3. 8.3. Displaying Messages
      4. 8.4. Using Variables
        1. 8.4.1. Environment variables
        2. 8.4.2. User variables
        3. 8.4.3. The backtick
      5. 8.5. Redirecting Input and Output
        1. 8.5.1. Output redirection
        2. 8.5.2. Input redirection
      6. 8.6. Pipes
      7. 8.7. Performing Math
        1. 8.7.1. The expr command
        2. 8.7.2. Using brackets
        3. 8.7.3. A floating-point solution
          1. 8.7.3.1. The basics of bc
          2. 8.7.3.2. Using bc in scripts
      8. 8.8. Exiting the Script
        1. 8.8.1. Checking the exit status
        2. 8.8.2. The exit command
      9. 8.9. Summary
    2. 9. Using Structured Commands
      1. 9.1. Working with the if-then Statement
      2. 9.2. The if-then-else Statement
      3. 9.3. Nesting ifs
      4. 9.4. The test Command
        1. 9.4.1. Numeric comparisons
        2. 9.4.2. String comparisons
          1. 9.4.2.1. String equality
          2. 9.4.2.2. String order
          3. 9.4.2.3. String size
        3. 9.4.3. File comparisons
          1. 9.4.3.1. Checking directories
          2. 9.4.3.2. Checking if an object exists
          3. 9.4.3.3. Checking for a file
          4. 9.4.3.4. Can you read it?
          5. 9.4.3.5. Checking for empty files
          6. 9.4.3.6. Checking if you can write to a file
          7. 9.4.3.7. Checking if you can run a file
          8. 9.4.3.8. Checking ownership
          9. 9.4.3.9. Checking file date
      5. 9.5. Compound Condition Testing
      6. 9.6. Advanced if-then Features
        1. 9.6.1. Using double parentheses
        2. 9.6.2. Using double brackets
      7. 9.7. The case Command
      8. 9.8. Summary
    3. 10. More Structured Commands
      1. 10.1. The for Command
        1. 10.1.1. Reading values in a list
        2. 10.1.2. Reading complex values in a list
        3. 10.1.3. Reading a list from a variable
        4. 10.1.4. Reading values from a command
        5. 10.1.5. Changing the field separator
        6. 10.1.6. Reading a directory using wildcards
      2. 10.2. The C-Style for Command
        1. 10.2.1. The C language for command
        2. 10.2.2. Using multiple variables
      3. 10.3. The while Command
        1. 10.3.1. Basic while format
        2. 10.3.2. Using multiple test commands
      4. 10.4. The until Command
      5. 10.5. Nesting Loops
      6. 10.6. Looping on File Data
      7. 10.7. Controlling the Loop
        1. 10.7.1. The break command
          1. 10.7.1.1. Breaking out of a single loop
          2. 10.7.1.2. Breaking out of an inner loop
          3. 10.7.1.3. Breaking out of an outer loop
        2. 10.7.2. The continue command
      8. 10.8. Processing the Output of a Loop
      9. 10.9. Summary
    4. 11. Handling User Input
      1. 11.1. Command Line Parameters
        1. 11.1.1. Reading parameters
        2. 11.1.2. Reading the program name
        3. 11.1.3. Testing parameters
      2. 11.2. Special Parameter Variables
        1. 11.2.1. Counting parameters
        2. 11.2.2. Grabbing all the data
      3. 11.3. Being Shifty
      4. 11.4. Working With Options
        1. 11.4.1. Finding your options
          1. 11.4.1.1. Processing simple options
          2. 11.4.1.2. Separating options from parameters
          3. 11.4.1.3. Processing options with values
        2. 11.4.2. Using the getopt command
          1. 11.4.2.1. The command format
          2. 11.4.2.2. Using getopt in your scripts
        3. 11.4.3. The more advanced getopts
      5. 11.5. Standardizing Options
      6. 11.6. Getting User Input
        1. 11.6.1. Basic reading
        2. 11.6.2. Timing out
        3. 11.6.3. Silent reading
        4. 11.6.4. Reading from a file
      7. 11.7. Summary
    5. 12. Presenting Data
      1. 12.1. Understanding Input and Output
        1. 12.1.1. Standard file descriptors
          1. 12.1.1.1. STDIN
          2. 12.1.1.2. STDOUT
          3. 12.1.1.3. STDERR
        2. 12.1.2. Redirecting errors
          1. 12.1.2.1. Redirecting just errors
          2. 12.1.2.2. Redirecting errors and data
      2. 12.2. Redirecting Output in Scripts
        1. 12.2.1. Temporary redirections
        2. 12.2.2. Permanent redirections
      3. 12.3. Redirecting Input in Scripts
      4. 12.4. Creating Your Own Redirection
        1. 12.4.1. Creating output file descriptors
        2. 12.4.2. Redirecting file descriptors
        3. 12.4.3. Creating input file descriptors
        4. 12.4.4. Creating a read/write file descriptor
        5. 12.4.5. Closing file descriptors
      5. 12.5. Listing Open File Descriptors
      6. 12.6. Suppressing Command Output
      7. 12.7. Using Temporary Files
        1. 12.7.1. Creating a local temporary file
        2. 12.7.2. Creating a temporary file in /tmp
        3. 12.7.3. Creating a temporary directory
      8. 12.8. Logging Messages
      9. 12.9. Summary
    6. 13. Script Control
      1. 13.1. Handling Signals
        1. 13.1.1. Linux signals revisited
        2. 13.1.2. Generating signals
          1. 13.1.2.1. Interrupting a process
          2. 13.1.2.2. Pausing a process
        3. 13.1.3. Trapping signals
        4. 13.1.4. Trapping a script exit
        5. 13.1.5. Removing a trap
      2. 13.2. Running Scripts in Background Mode
        1. 13.2.1. Running in the background
        2. 13.2.2. Running multiple background jobs
        3. 13.2.3. Exiting the terminal
      3. 13.3. Running Scripts without a Console
      4. 13.4. Job Control
        1. 13.4.1. Viewing jobs
        2. 13.4.2. Restarting stopped jobs
      5. 13.5. Being Nice
        1. 13.5.1. The nice command
        2. 13.5.2. The renice command
      6. 13.6. Running Like Clockwork
        1. 13.6.1. Scheduling a job using the at command
          1. 13.6.1.1. The at command format
          2. 13.6.1.2. Retrieving job output
          3. 13.6.1.3. Listing pending jobs
          4. 13.6.1.4. Removing jobs
        2. 13.6.2. Using the batch command
        3. 13.6.3. Scheduling regular scripts
          1. 13.6.3.1. The cron table
          2. 13.6.3.2. Building the cron table
          3. 13.6.3.3. The anacron program
      7. 13.7. Start At the Beginning
        1. 13.7.1. Starting your scripts at boot
          1. 13.7.1.1. The boot process
          2. 13.7.1.2. Defining your scripts
        2. 13.7.2. Starting with a new shell
      8. 13.8. Summary
  8. III. Advanced Shell Scripting
    1. 14. Creating Functions
      1. 14.1. Basic Script Functions
        1. 14.1.1. Creating a function
        2. 14.1.2. Using functions
      2. 14.2. Returning a Value
        1. 14.2.1. The default exit status
        2. 14.2.2. Using the return command
        3. 14.2.3. Using function output
      3. 14.3. Using Variables in Functions
        1. 14.3.1. Passing parameters to a function
        2. 14.3.2. Handling variables in a function
          1. 14.3.2.1. Global variables
          2. 14.3.2.2. Local variables
      4. 14.4. Array Variables and Functions
        1. 14.4.1. Passing arrays to functions
        2. 14.4.2. Returning arrays from functions
      5. 14.5. Function Recursion
      6. 14.6. Creating a Library
      7. 14.7. Using Functions on the Command Line
        1. 14.7.1. Creating functions on the command line
        2. 14.7.2. Defining functions in the .bashrc file
          1. 14.7.2.1. Directly defining functions
          2. 14.7.2.2. Sourcing function files
      8. 14.8. Summary
    2. 15. Adding Color to Scripts
      1. 15.1. Creating Text Menus
        1. 15.1.1. Create the menu layout
        2. 15.1.2. Create the menu functions
        3. 15.1.3. Add the menu logic
        4. 15.1.4. Putting it all together
        5. 15.1.5. Using the select command
      2. 15.2. Adding Color
        1. 15.2.1. The ANSI escape codes
        2. 15.2.2. Displaying ANSI escape codes
        3. 15.2.3. Using colors in scripts
      3. 15.3. Doing Windows
        1. 15.3.1. The dialog package
          1. 15.3.1.1. The msgbox widget
          2. 15.3.1.2. The yesno widget
          3. 15.3.1.3. The inputbox widget
          4. 15.3.1.4. The textbox widget
          5. 15.3.1.5. The menu widget
          6. 15.3.1.6. The fselect widget
        2. 15.3.2. The dialog options
        3. 15.3.3. Using the dialog command in a script
      4. 15.4. Getting Graphic
        1. 15.4.1. The KDE environment
          1. 15.4.1.1. kdialog widgets
          2. 15.4.1.2. Using kdialog
        2. 15.4.2. The GNOME environment
          1. 15.4.2.1. zenity widgets
          2. 15.4.2.2. Using zenity in scripts
      5. 15.5. Summary
    3. 16. Introducing sed and gawk
      1. 16.1. Text Manipulation
        1. 16.1.1. The sed editor
          1. 16.1.1.1. Defining an editor command in the command line
          2. 16.1.1.2. Using multiple editor commands in the command line
          3. 16.1.1.3. Reading editor commands from a file
        2. 16.1.2. The gawk program
          1. 16.1.2.1. The gawk command format
          2. 16.1.2.2. Reading the program script from the command line
          3. 16.1.2.3. Using data field variables
          4. 16.1.2.4. Using multiple commands in the program script
          5. 16.1.2.5. Reading the program from a file
          6. 16.1.2.6. Running scripts before processing data
          7. 16.1.2.7. Running scripts after processing data
      2. 16.2. The sed Editor Basics
        1. 16.2.1. More substitution options
          1. 16.2.1.1. Substitution flags
          2. 16.2.1.2. Replacement characters
        2. 16.2.2. Using addresses
          1. 16.2.2.1. Numeric line addressing
          2. 16.2.2.2. Using text pattern filters
          3. 16.2.2.3. Grouping commands
        3. 16.2.3. Deleting lines
        4. 16.2.4. Inserting and appending text
        5. 16.2.5. Changing lines
        6. 16.2.6. The transform command
        7. 16.2.7. Printing revisited
          1. 16.2.7.1. Printing lines
          2. 16.2.7.2. Printing line numbers
          3. 16.2.7.3. Listing lines
        8. 16.2.8. Using files with sed
          1. 16.2.8.1. Writing to a file
          2. 16.2.8.2. Reading data from a file
      3. 16.3. Summary
    4. 17. Regular Expressions
      1. 17.1. What Are Regular Expressions?
        1. 17.1.1. A definition
        2. 17.1.2. Types of regular expressions
      2. 17.2. Defining BRE Patterns
        1. 17.2.1. Plain text
        2. 17.2.2. Special characters
        3. 17.2.3. Anchor characters
          1. 17.2.3.1. Starting at the beginning
          2. 17.2.3.2. Looking for the ending
          3. 17.2.3.3. Combining anchors
        4. 17.2.4. The dot character
        5. 17.2.5. Character classes
        6. 17.2.6. Negating character classes
        7. 17.2.7. Using ranges
        8. 17.2.8. Special character classes
        9. 17.2.9. The asterisk
      3. 17.3. Extended Regular Expressions
        1. 17.3.1. The question mark
        2. 17.3.2. The plus sign
        3. 17.3.3. Using braces
        4. 17.3.4. The pipe symbol
        5. 17.3.5. Grouping expressions
      4. 17.4. Regular Expressions in Action
        1. 17.4.1. Counting directory files
        2. 17.4.2. Validating a phone number
        3. 17.4.3. Parsing an e-mail address
      5. 17.5. Summary
    5. 18. Advanced sed
      1. 18.1. Multiline Commands
        1. 18.1.1. The next commands
          1. 18.1.1.1. The single-line next command
          2. 18.1.1.2. Combining lines of text
        2. 18.1.2. The multiline delete command
        3. 18.1.3. The multiline print command
      2. 18.2. The Hold Space
      3. 18.3. Negating a Command
      4. 18.4. Changing the Flow
        1. 18.4.1. Branching
        2. 18.4.2. Testing
      5. 18.5. Pattern Replacement
        1. 18.5.1. The ampersand
        2. 18.5.2. Replacing individual words
      6. 18.6. Using sed in Scripts
        1. 18.6.1. Using wrappers
        2. 18.6.2. Redirecting sed output
      7. 18.7. Creating sed Utilities
        1. 18.7.1. Double spacing lines
        2. 18.7.2. Double spacing files that may have blanks
        3. 18.7.3. Numbering lines in a file
        4. 18.7.4. Printing last lines
        5. 18.7.5. Deleting lines
          1. 18.7.5.1. Deleting consecutive blank lines
          2. 18.7.5.2. Deleting leading blank lines
          3. 18.7.5.3. Deleting trailing blank lines
        6. 18.7.6. Removing HTML tags
      8. 18.8. Summary
    6. 19. Advanced gawk
      1. 19.1. Using Variables
        1. 19.1.1. Built-in variables
          1. 19.1.1.1. The field and record separator variables
          2. 19.1.1.2. Data variables
        2. 19.1.2. User-defined variables
          1. 19.1.2.1. Assigning variables in scripts
          2. 19.1.2.2. Assigning variables in the command line
      2. 19.2. Working with Arrays
        1. 19.2.1. Defining array variables
        2. 19.2.2. Iterating through array variables
        3. 19.2.3. Deleting array variables
      3. 19.3. Using Patterns
        1. 19.3.1. Regular expressions
        2. 19.3.2. The matching operator
        3. 19.3.3. Mathematical expressions
      4. 19.4. Structured Commands
        1. 19.4.1. The if statement
        2. 19.4.2. The while statement
        3. 19.4.3. The do-while statement
        4. 19.4.4. The for statement
      5. 19.5. Formatted Printing
      6. 19.6. Built-in Functions
        1. 19.6.1. Mathematical functions
        2. 19.6.2. String functions
        3. 19.6.3. Time functions
      7. 19.7. User-Defined Functions
        1. 19.7.1. Defining a function
        2. 19.7.2. Using your functions
        3. 19.7.3. Creating a function library
      8. 19.8. Summary
  9. IV. Alternative Linux Shells
    1. 20. The ash Shell
      1. 20.1. What Is the ash Shell?
      2. 20.2. The Original ash Shell
        1. 20.2.1. The Original ash command line parameters
        2. 20.2.2. The original ash built-in commands
          1. 20.2.2.1. The bltin command
          2. 20.2.2.2. The hash command
          3. 20.2.2.3. The lc command
        3. 20.2.3. The ash shell files
      3. 20.3. The dash Shell
        1. 20.3.1. The dash command line parameters
        2. 20.3.2. The dash environment variables
          1. 20.3.2.1. Default environment variables
          2. 20.3.2.2. Positional parameters
          3. 20.3.2.3. User-defined environment variables
        3. 20.3.3. The dash built-in commands
          1. 20.3.3.1. The printf command
          2. 20.3.3.2. The ulimit command
      4. 20.4. Scripting in dash
        1. 20.4.1. Creating ash and dash scripts
        2. 20.4.2. Things that won't work
          1. 20.4.2.1. Using arithmetic
          2. 20.4.2.2. The test command
          3. 20.4.2.3. The echo statement options
          4. 20.4.2.4. The function command
      5. 20.5. Summary
    2. 21. The tcsh Shell
      1. 21.1. What Is the tcsh Shell?
      2. 21.2. The tcsh Shell Components
        1. 21.2.1. The tcsh command line parameters
        2. 21.2.2. The tcsh files
        3. 21.2.3. The tcsh login files
        4. 21.2.4. Shell startup files
        5. 21.2.5. The logout files
        6. 21.2.6. The tcsh environment variables
        7. 21.2.7. Shell variables
        8. 21.2.8. Environment variables
        9. 21.2.9. Setting variables in tcsh
        10. 21.2.10. Using the set command
        11. 21.2.11. Using the setenv command
        12. 21.2.12. The tcsh built-in commands
      3. 21.3. Scripting in tcsh
        1. 21.3.1. Working with variables
        2. 21.3.2. Array variables
        3. 21.3.3. Handling mathematical operations
        4. 21.3.4. Structured commands
        5. 21.3.5. The if statements
        6. 21.3.6. The foreach statement
        7. 21.3.7. The while statement
        8. 21.3.8. The switch command
      4. 21.4. Summary
    3. 22. The Korn Shell
      1. 22.1. The Korn Shell History
      2. 22.2. The Parts of the ksh93 Shell
        1. 22.2.1. Command line parameters
        2. 22.2.2. Default files
        3. 22.2.3. Environment variables
          1. 22.2.3.1. Random numbers
          2. 22.2.3.2. Defining the variable type
          3. 22.2.3.3. Using arrays
          4. 22.2.3.4. Compound variables
          5. 22.2.3.5. Special variable subscripts
        4. 22.2.4. Built-in commands
      3. 22.3. Scripting in the ksh93 Shell
        1. 22.3.1. Mathematical operations
          1. 22.3.1.1. Performing calculations
          2. 22.3.1.2. Mathematical functions
        2. 22.3.2. Structured commands
          1. 22.3.2.1. The if-then-else statement
          2. 22.3.2.2. The while and until loops
        3. 22.3.3. Command redirection
        4. 22.3.4. Discipline functions
      4. 22.4. Summary
    4. 23. The zsh Shell
      1. 23.1. History of the zsh Shell
      2. 23.2. Parts of the zsh Shell
        1. 23.2.1. Shell options
          1. 23.2.1.1. Shell state
          2. 23.2.1.2. Shell emulation
          3. 23.2.1.3. Initialization
          4. 23.2.1.4. Scripts and functions
        2. 23.2.2. The zsh shell files
          1. 23.2.2.1. The shell startup files
          2. 23.2.2.2. The shell login files
          3. 23.2.2.3. The interactive shell files
          4. 23.2.2.4. The shell logout files
        3. 23.2.3. Environment variables
        4. 23.2.4. Built-in commands
          1. 23.2.4.1. Core built-in commands
          2. 23.2.4.2. Add-in modules
          3. 23.2.4.3. Viewing, adding, and removing modules
      3. 23.3. Scripting with zsh
        1. 23.3.1. Mathematical operations
          1. 23.3.1.1. Performing calculations
          2. 23.3.1.2. Mathematical functions
        2. 23.3.2. Structured commands
        3. 23.3.3. Functions
      4. 23.4. Summary
  10. V. Advanced Topics
    1. 24. Using a Database
      1. 24.1. The MySQL Database
        1. 24.1.1. Installing MySQL
        2. 24.1.2. Completing the MySQL configuration
          1. 24.1.2.1. Initializing the database files
          2. 24.1.2.2. Starting the MySQL server
          3. 24.1.2.3. Securing the MySQL user account
        3. 24.1.3. The MySQL client interface
          1. 24.1.3.1. Connecting to the server
          2. 24.1.3.2. The mysql commands
        4. 24.1.4. Creating MySQL database objects
          1. 24.1.4.1. Creating a database
          2. 24.1.4.2. Creating a user account
      2. 24.2. The PostgreSQL Database
        1. 24.2.1. Installing PostgreSQL
        2. 24.2.2. The PostgreSQL command interface
          1. 24.2.2.1. Connecting to the server
          2. 24.2.2.2. The psql commands
        3. 24.2.3. Creating PostgreSQL database objects
          1. 24.2.3.1. Creating a database object
          2. 24.2.3.2. Creating user accounts
      3. 24.3. Working with Tables
        1. 24.3.1. Creating a table
        2. 24.3.2. Inserting and deleting data
        3. 24.3.3. Querying data
      4. 24.4. Using the Database in Your Scripts
        1. 24.4.1. Connecting to the databases
          1. 24.4.1.1. Finding the programs
          2. 24.4.1.2. Logging into the server
        2. 24.4.2. Sending commands to the server
        3. 24.4.3. Formatting data
          1. 24.4.3.1. Assigning output to a variable
          2. 24.4.3.2. Using formatting tags
      5. 24.5. Summary
    2. 25. Using the Web
      1. 25.1. The Lynx Program
        1. 25.1.1. Installing Lynx
        2. 25.1.2. The lynx command line
        3. 25.1.3. The Lynx configuration file
        4. 25.1.4. The Lynx environment variables
        5. 25.1.5. Capturing data from Lynx
      2. 25.2. The cURL Program
        1. 25.2.1. Installing cURL
        2. 25.2.2. The cURL command line
        3. 25.2.3. Exploring with curl
      3. 25.3. Networking with zsh
        1. 25.3.1. The TCP module
        2. 25.3.2. The client/server paradigm
        3. 25.3.3. Client/server programming with zsh
          1. 25.3.3.1. The server program
          2. 25.3.3.2. The client program
          3. 25.3.3.3. Running the programs
      4. 25.4. Summary
    3. 26. Using E-Mail
      1. 26.1. The Basics of Linux E-Mail
        1. 26.1.1. E-Mail in Linux
        2. 26.1.2. The Mail Transfer Agent
        3. 26.1.3. The Mail Delivery Agent
        4. 26.1.4. The Mail User Agent
          1. 26.1.4.1. Mailx
          2. 26.1.4.2. Mutt
          3. 26.1.4.3. Graphical e-mail clients
      2. 26.2. Setting Up Your Server
        1. 26.2.1. sendmail
          1. 26.2.1.1. Parts of the sendmail program
          2. 26.2.1.2. The sendmail.cf file
        2. 26.2.2. Postfix
          1. 26.2.2.1. Parts of the Postfix system
          2. 26.2.2.2. Postfix configuration files
      3. 26.3. Sending a Message with Mailx
      4. 26.4. The Mutt Program
        1. 26.4.1. Installing Mutt
        2. 26.4.2. The Mutt command line
        3. 26.4.3. Using Mutt
      5. 26.5. Summary
    4. 27. Shell Scripts for Administrators
      1. 27.1. Monitoring System Statistics
        1. 27.1.1. Monitoring disk free space
          1. 27.1.1.1. The required functions
          2. 27.1.1.2. Creating the script
          3. 27.1.1.3. Running the script
        2. 27.1.2. Catching disk hogs
          1. 27.1.2.1. The required functions
          2. 27.1.2.2. Creating the script
          3. 27.1.2.3. Running the script
        3. 27.1.3. Watching CPU and memory usage
          1. 27.1.3.1. The required functions
          2. 27.1.3.2. Creating the capture script
          3. 27.1.3.3. Generating the report script
          4. 27.1.3.4. Running the script
      2. 27.2. Performing Backups
        1. 27.2.1. Archiving data files
          1. 27.2.1.1. The required functions
          2. 27.2.1.2. Creating a daily archive script
          3. 27.2.1.3. Creating an hourly archive script
        2. 27.2.2. Storing backups off-site
          1. 27.2.2.1. The required functions
          2. 27.2.2.2. Creating the script
          3. 27.2.2.3. Running the script
      3. 27.3. Summary
    5. A. Quick Guide to bash Commands
      1. A.1. Built-In Commands
      2. A.2. Bash Commands
      3. A.3. Environment Variables
    6. B. Quick Guide to sed and gawk
      1. B.1. The sed Editor
        1. B.1.1. Starting the sed editor
        2. B.1.2. sed commands
          1. B.1.2.1. Substitution
          2. B.1.2.2. Addressing
          3. B.1.2.3. Deleting lines
          4. B.1.2.4. Inserting and appending text
          5. B.1.2.5. Changing lines
          6. B.1.2.6. Transform command
          7. B.1.2.7. Printing lines
          8. B.1.2.8. Writing to a file
          9. B.1.2.9. Reading from a file
      2. B.2. The gawk program
        1. B.2.1. The gawk command format
        2. B.2.2. Using gawk
          1. B.2.2.1. Reading the program script from the command line
          2. B.2.2.2. Using multiple commands in the program script
          3. B.2.2.3. Reading the program from a file
          4. B.2.2.4. Running scripts before processing data
          5. B.2.2.5. Running scripts after processing data
        3. B.2.3. The gawk variables
          1. B.2.3.1. Built-in variables
          2. B.2.3.2. Assigning variables in scripts
          3. B.2.3.3. Assigning variables in the command line
        4. B.2.4. The gawk program features
          1. B.2.4.1. Regular expressions
          2. B.2.4.2. The matching operator
          3. B.2.4.3. Mathematical expressions
          4. B.2.4.4. Structured commands
    7. C. Comparing Shells
      1. C.1. Variables
        1. C.1.1. Environment variables
        2. C.1.2. User-defined variables
        3. C.1.3. Array variables
      2. C.2. Structured Commands
        1. C.2.1. The if-then, while, and until statements
        2. C.2.2. The for statement
      3. C.3. Mathematical Operations