Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

One of the steepest Unix/Linux learning curves is the sheer number of built-in commands, all of which have many options (most of which you'll never use), and the more advanced commands are extremely complex.

To help address this, this page introduces a number of built-in Linux utilities along with some of their common options, by category.

...

  • Default field separators
    • Tab is the default field separator for cut
    • whitespace (one or more spaces or Tabs) is the default field separator for awk
  • Re-ordering
    • cut cannot re-order fields
    • awk can re-order fields, based on the order you specify
  • awk is a full-featured programming language while cut is just a single-purpose utility.

grep and regular expressions

  • grep -P '<pattern>' searches for <pattern> in its input, and only outputs lines containing it
    • always enclose '<pattern>' in single quotes to inhibit shell evaluation!
      • pattern-matching metacharacters are very different from those in the shell
    • -P says to use Perl patterns, which are much more powerful than standard grep patterns
    • -v (inverse match) – only print lines with no match
    • -n (line number) – prefix output with the line number of the match
    • -i  (case insensitive) – ignore case when matching
    • -l says return only the names of files that do contain the pattern match
    • -L says return only the names of files that do not contain the pattern match
    • -c says just return a count of line matches
    • -A <n> (After) and -B <n> (Before) – output '<n>' number of lines after or before a match

...