Command Line Fundamentals

Book description

Master shell basics and Unix tools and discover easy commands to perform complex tasks with speed

Key Features

  • Learn why the Bash shell is widely used on Linux and iOS
  • Explore advanced shell concepts, such as pipes and redirection
  • Understand how to use Unix command-line tools as building blocks for different tasks

Book Description

The most basic interface to a computer - the command line - remains the most flexible and powerful way of processing data and performing and automating various day-to-day tasks.

Command Line Fundamentals begins by exploring the basics, and then focuses on the most common tool, the Bash shell (which is standard on all Linux and iOS systems). As you make your way through the book, you'll explore the traditional Unix command-line programs as implemented by the GNU project. You'll also learn to use redirection and pipelines to assemble these programs to solve complex problems.

By the end of this book, you'll have explored the basics of shell scripting, allowing you to easily and quickly automate tasks.

What you will learn

  • Use the Bash shell to run commands
  • Utilize basic Unix utilities such as cat, tr, sort, and uniq
  • Explore shell wildcards to manage groups of files
  • Apply useful keyboard shortcuts in shell
  • Employ redirection and pipes to process data
  • Write both basic and advanced shell scripts to automate tasks

Who this book is for

Command Line Fundamentals is for programmers who use GUIs but want to understand how to use the command line to complete tasks faster.

Table of contents

  1. Preface
    1. About the Book
      1. About the Author
      2. Objectives
      3. Audience
      4. Approach
      5. Hardware Requirements
      6. Software Requirements
      7. Installation and Setup
      8. Guidelines and Tips for using the VM
      9. Installing the Code Bundle
      10. Conventions
      11. Additional Resources
  2. Introduction to the Command Line
    1. Introduction
    2. Command Line: History, Shells, and Terminology
      1. History of the Command Line
      2. Command-Line Shells
      3. Command-Line Terminology
    3. Exploring the Filesystem
      1. Filesystems
      2. Navigating Filesystems
      3. Exercise 1: Exploring Filesystem Contents
      4. Manipulating a Filesystem
      5. Exercise 2: Manipulating the Filesystem
      6. Activity 1: Navigating the Filesystem and Viewing Files
      7. Activity 2: Modifying the Filesystem
    4. Shell History Recall, Editing, and Autocompletion
      1. Command History Recall
      2. Exercise 3: Exploring Shell History
      3. Command-Line Shortcuts
      4. Exercise 4: Using Shell Keyboard Shortcuts
      5. Command-Line Autocompletion
      6. Exercise 5: Completing a Folder Path
      7. Exercise 6: Completing a Command
      8. Exercise 7: Completing a Command using Options
      9. Activity 3: Command-Line Editing
    5. Shell Wildcards and Globbing
      1. Wildcard Syntax and Semantics
      2. Wildcard Expansion or Globbing
      3. Exercise 8: Using Wildcards
      4. Activity 4: Using Simple Wildcards
      5. Activity 5: Using Directory Wildcards
    6. Summary
  3. Command-Line Building Blocks
    1. Introduction
    2. Redirection
      1. Input and Output Streams
      2. Use of Operators for Redirection
      3. Using Multiple Redirections
      4. Heredocs and Herestrings
      5. Buffering
      6. Exercise 9: Working with Command Redirection
    3. Pipes
      1. Exercise 10: Working with Pipes
    4. Text-Processing Commands
      1. Shell Input Concepts
      2. Filtering Commands
      3. Exercise 11: Working with Filtering Commands
      4. Transformation Commands
      5. Exercise 12: Working with Transformation Commands
      6. Activity 6: Processing Tabular Data – Reordering Columns
      7. Activity 7: Data Analysis
    5. Summary
  4. Advanced Command-Line Concepts
    1. Introduction
    2. Command Lists
      1. Command List Operators
      2. Using Multiple Operators
      3. Command Grouping
      4. Exercise 13: Using Command Lists
    3. Job Control
      1. Keyboard Shortcuts for Controlling Jobs
      2. Commands for Controlling Jobs
    4. Regular Expressions
      1. Elements
      2. Quantifiers
      3. Anchoring
      4. Subexpressions and Backreferences
      5. Exercise 14: Using Regular Expressions
      6. Activity 8: Word Matching with Regular Expressions
    5. Shell Expansion
      1. Environment Variables and Variable Expansion
      2. Arithmetic Expansion
      3. Brace Expansion
      4. Recursive Expansion with eval
      5. Command Substitution
      6. Process Substitution
      7. Exercise 15: Using Shell Expansions
      8. Activity 9: String Processing with eval and Shell Expansion
    6. Summary
  5. Shell Scripting
    1. Introduction
    2. Conditionals and Loops
      1. Conditional Expressions
      2. Conditional Statements
      3. Loops
      4. Loop Control
    3. Shell Functions
      1. Function Definition
      2. Function Arguments
      3. Return Values
      4. Local Variables, Scope, and Recursion
      5. Exercise 16: Using Conditional Statements, Loops, and Functions
    4. Shell Line Input
      1. Line Input Commands
      2. Internal Field Separator
      3. Exercise 17: Using Shell Input Interactively
    5. Shell Scripts
      1. Shell Command Categories
      2. Program Launch Process
      3. Script Interpreters
    6. Practical Case Study 1: Chess Game Extractor
      1. Understanding the Problem
      2. Exercise 18: Chess Game Extractor – Parsing a PGN File
      3. Exercise 19: Chess Game Extractor – Extracting a Desired Game
      4. Refining Our Script
      5. Exercise 20: Chess Game Extractor – Handling Options
      6. Adding Features
      7. Exercise 21: Chess Game Extractor – Counting Game Moves
    7. Tips and Tricks
      1. Suppressing Command Output
      2. Arithmetic Expansion
      3. Declaring Typed Variables
      4. Numeric for Loops
      5. echo
      6. Array Reverse Indexing
      7. shopt
      8. Extended Wildcards
      9. man and info Pages
      10. shellcheck
      11. Activity 10: PGN Game Extractor Enhancement
    8. Practical Case Study 2: NYC Yellow Taxi Trip Analysis
      1. Understanding the Dataset
      2. Exercise 22: Taxi Trip Analysis – Extracting Trip Time
      3. Exercise 23: Taxi Trip Analysis – Calculating Average Trip Speed
      4. Exercise 24: Taxi Trip Analysis – Calculating Average Fare
      5. Activity 11: Shell Scripting – NYC Taxi Trip Analysis
    9. Summary
  6. Appendix
    1. Chapter 1: Introduction to the Command Line
      1. Activity 1: Navigating the Filesystem and Viewing Files
      2. Activity 2: Modifying the Filesystem
      3. Activity 3: Command-Line Editing
      4. Activity 4: Using Simple Wildcards
      5. Activity 5: Using Directory Wildcards
    2. Chapter 2: Command-Line Building Blocks
      1. Activity 6: Processing Tabular Data – Reordering Columns
      2. Activity 7: Data Analysis
    3. Chapter 3: Advanced Command-Line Concepts
      1. Activity 8: Word Matching with Regular Expressions
      2. Activity 9: String Processing with eval and Shell Expansion
    4. Chapter 4: Shell Scripting
      1. Activity 10: PGN Game Extractor Enhancement
      2. Activity 11: Shell Scripting – NYC Taxi Trip Analysis

Product information

  • Title: Command Line Fundamentals
  • Author(s): Vivek N
  • Release date: December 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789807769