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

Book Description

The authoritative guide to Linux command line and shell scripting completely updated and revised [it's not a guide to Linux as a whole just to scripting]

The Linux command line allows you to type specific Linux commands directly to the system so that you can easily manipulate files and query system resources, thereby permitting you to automate commonly used functions and even schedule those programs to run automatically. This new edition is packed with new and revised content, reflecting the many changes to new Linux versions, including coverage of alternative shells to the default bash shell. For this edition, the author has teamed up with another Linux expert with their shared expertise, they take you beyond the basics of shell scripting and guide you through using shell scripting for higher-level applications that are commonly found in Linux environments. In addition, this edition features a host of real-world examples, so you can see how the scripts work in application.

  • Reflects changes to new Linux versions and covers alternate shells to the default bash shell

  • Offers new chapters on working with file system commands and software installation commands

  • Includes a plethora of real-world examples of advanced shell scripting

  • Shows how to use shell scripts in a graphical desktop environment

With Linux Command Line and Shell Scripting Bible you'll learn to manage file systems, install software, write scripts for graphical desktops, work with alternative shells, and more.

Table of Contents

  1. Cover
  2. Title Page
  3. Copyright
  4. Dedication
  5. Credits
  6. About the Authors
  7. About the Technical Editor
  8. Acknowledgments
  9. Introduction
    1. Who Should Read This Book
    2. How This Book Is Organized
    3. Minimum Requirements
    4. Where to Go from Here
  10. Part I: The Linux Command Line
    1. Chapter 1: Starting with Linux Shells
      1. What Is Linux?
      2. Linux Distributions
      3. Summary
    2. Chapter 2: Getting to the Shell
      1. Terminal Emulation
      2. The terminfo Database
      3. The Linux Console
      4. The xterm Terminal
      5. The Konsole Terminal
      6. The GNOME Terminal
      7. Summary
    3. Chapter 3: Basic bash Shell Commands
      1. Starting the Shell
      2. The Shell Prompt
      3. The bash Manual
      4. Filesystem Navigation
      5. File and Directory Listing
      6. File Handling
      7. Directory Handling
      8. Viewing File Contents
      9. Summary
    4. Chapter 4: More bash Shell Commands
      1. Monitoring Programs
      2. Monitoring Disk Space
      3. Working with Data Files
      4. Summary
    5. Chapter 5: Using Linux Environment Variables
      1. What Are Environment Variables?
      2. Setting Environment Variables
      3. Removing Environment Variables
      4. Default Shell Environment Variables
      5. Setting the PATH Environment Variable
      6. Locating System Environment Variables
      7. Variable Arrays
      8. Using Command Aliases
      9. Summary
    6. Chapter 6: Understanding Linux File Permissions
      1. Linux Security
      2. Using Linux Groups
      3. Decoding File Permissions
      4. Changing Security Settings
      5. Sharing Files
      6. Summary
    7. Chapter 7: Managing Filesystems
      1. Exploring Linux Filesystems
      2. Working with Filesystems
      3. Logical Volume Managers
      4. Summary
    8. Chapter 8: Installing Software
      1. Package Management Primer
      2. The Debian-Based Systems
      3. The Red Hat–Based Systems
      4. Installing from Source Code
      5. Summary
    9. Chapter 9: Working with Editors
      1. The vim Editor
      2. The emacs Editor
      3. The KDE Family of Editors
      4. The GNOME Editor
      5. Summary
  11. Part II: Shell Scripting Basics
    1. Chapter 10: Basic Script Building
      1. Using Multiple Commands
      2. Creating a Script File
      3. Displaying Messages
      4. Using Variables
      5. Redirecting Input and Output
      6. Pipes
      7. Performing Math
      8. Exiting the Script
      9. Summary
    2. Chapter 11: Using Structured Commands
      1. Working with the if-then Statement
      2. The if-then-else Statement
      3. Nesting ifs
      4. The test Command
      5. Compound Condition Testing
      6. Advanced if-then Features
      7. The case Command
      8. Summary
    3. Chapter 12: More Structured Commands
      1. The for Command
      2. The C-Style for Command
      3. The while Command
      4. The until Command
      5. Nesting Loops
      6. Looping on File Data
      7. Controlling the Loop
      8. Processing the Output of a Loop
      9. Summary
    4. Chapter 13: Handling User Input
      1. Command Line Parameters
      2. Special Parameter Variables
      3. Being Shifty
      4. Working with Options
      5. Standardizing Options
      6. Getting User Input
      7. Summary
    5. Chapter 14: Presenting Data
      1. Understanding Input and Output
      2. Redirecting Output in Scripts
      3. Redirecting Input in Scripts
      4. Creating Your Own Redirection
      5. Listing Open File Descriptors
      6. Suppressing Command Output
      7. Using Temporary Files
      8. Logging Messages
      9. Summary
    6. Chapter 15: Script Control
      1. Handling Signals
      2. Running Scripts in Background Mode
      3. Running Scripts Without a Console
      4. Job Control
      5. Being Nice
      6. Running Like Clockwork
      7. Summary
  12. Part III: Advanced Shell Scripting
    1. Chapter 16: Creating Functions
      1. Basic Script Functions
      2. Returning a Value
      3. Using Variables in Functions
      4. Array Variables and Functions
      5. Function Recursion
      6. Creating a Library
      7. Using Functions on the Command Line
      8. Summary
    2. Chapter 17: Writing Scripts for Graphical Desktops
      1. Creating Text Menus
      2. Doing Windows
      3. Getting Graphic
      4. Summary
    3. Chapter 18: Introducing sed and gawk
      1. Text Manipulation
      2. The sed Editor Basics
      3. Summary
    4. Chapter 19: Regular Expressions
      1. What Are Regular Expressions?
      2. Defining BRE Patterns
      3. Extended Regular Expressions
      4. Regular Expressions in Action
      5. Summary
    5. Chapter 20: Advanced sed
      1. Multiline Commands
      2. The Hold Space
      3. Negating a Command
      4. Changing the Flow
      5. Pattern Replacement
      6. Using sed in Scripts
      7. Creating sed Utilities
      8. Summary
    6. Chapter 21: Advanced gawk
      1. Using Variables
      2. Working with Arrays
      3. Using Patterns
      4. Structured Commands
      5. Formatted Printing
      6. Built-in Functions
      7. User-Defined Functions
      8. Summary
    7. Chapter 22: Working with Alternative Shells
      1. What Is the dash Shell?
      2. The dash Shell Features
      3. Scripting in dash
      4. The zsh Shell
      5. Parts of the zsh Shell
      6. Scripting with zsh
      7. Summary
  13. Part IV: Advanced Shell Scripting Topics
    1. Chapter 23: Using a Database
      1. The MySQL Database
      2. The PostgreSQL Database
      3. Working with Tables
      4. Using the Database in Your Scripts
      5. Summary
    2. Chapter 24: Using the Web
      1. The Lynx Program
      2. The cURL Program
      3. Networking with zsh
      4. Summary
    3. Chapter 25: Using E-mail
      1. The Basics of Linux E-Mail
      2. Setting Up Your Server
      3. Sending a Message with Mailx
      4. The Mutt Program
      5. Summary
    4. Chapter 26: Writing Script Utilities
      1. Monitoring Disk Space
      2. Performing Backups
      3. Managing User Accounts
      4. Summary
    5. Chapter 27: Advanced Shell Scripts
      1. Monitoring System Statistics
      2. Problem-Tracking Database
      3. Summary
  14. Appendix A: Quick Guide to bash Commands
    1. Built-in Commands
    2. bash Commands
    3. Environment Variables
  15. Appendix B: Quick Guide to sed and gawk
    1. The sed Editor
    2. The gawk Program
  16. Index