Versions Compared

Key

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

...

  • The built-in history command lists the commands you've entered, each with a number.
    • You can re-execute any command in the history by typing an exclamation point ( ! ) then the number
    • e.g. !15 re-executes the 15th command in your history.
    • Only commands in your current bash session are in the history, but you can always save them for future reference, e.g. history > ~/history.20232024-11-0308.
  • Use Up arrow to retrieve any of the last 50+ commands you've typed, going backwards through your history.
    • You can then edit the retrieved line, and hit Enter (even in the middle of the command), and the shell will use that command.
  • The Down arrow "scrolls" forward from where you are in the command history.

...

A key to text manipulation is understanding Unix streams, which represent flows of characters. Every Unix program has three "built-in" streams: standard input, standard output and standard error

Image RemovedImage Added

Most programs/commands read input data from some source, then write output to some destination. A data source can be a file, but can also be standard input. Similarly, a data destination can be a file but can also be a stream such as standard output.

The power of the Linux command line is due in no small part to the power of piping. The pipe operator ( | ) connects one program's standard output to the next program's standard input.

piping.pngImage RemovedImage Added

The key to the power of piping is that most Unix commands can accept input from standard input instead of from files. So, for example, these two expressions appear equivalent:

...

Recall the three standard Unix streams: they each have a number, a name and redirection syntax:

Image RemovedImage Added

  • standard output is stream 1
    • redirect standard output to a file with a the > or 1> operator
      • a single > or 1> overwrites any existing data in the target file
      • a double >> or 1>> appends to any existing data in the target file
  • standard error is stream 2
    • redirect standard error to a file with a the 2> operator
      • a single 2> overwrites any existing data in the target file
      • a double 2>> appends to any existing data in the target file

...