Book Image

Command Line Fundamentals

By : Vivek Nagarajan
Book Image

Command Line Fundamentals

By: Vivek Nagarajan

Overview of this book

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.
Table of Contents (6 chapters)

Regular Expressions

A regular expression, also called a regex (plural regexes), is a kind of pattern-matching syntax, similar to wildcards, but much more powerful. A complete description of regexes would fill many chapters, so we will restrict ourselves to a reasonable subset in this chapter.

The most common use case of regexes is with the grep and sed commands, which we studied in the previous chapter. The basic operation we perform with a regex is to match it against some text:

  • grep can search for text matching a regex
  • sed can search and replace the text matching a regex with a specified replacement string

    Note

    Since the special characters in regex syntax overlap with those that the shell uses, always pass regexes in single quotes to ensure that the shell passes them literally to the command, without interpretation. Commands that accept regexes will handle escape sequences by themselves.

There are two kinds of regexes, that is, basic and extended...