Bonus: Pipe Operator

Bonus: Selecting commands containing redirection write operators from history and saving.

Pipe the STDOUT from the history command to grep and search all lines for a redirection write operator > and write the output to myhistory-write-commands.txt.

Solution

CLICK FOR ANSWER
history | grep '>' > myhistory-write-commands.txt

Verification

CLICK FOR ANSWER
cat myhistory-write-commands.txt

Example output:

  910  echo "Paul" > myname.txt
  913  echo "firstName=Paul" > myname.txt
  915  echo "lastName=Matthews" >> myname.txt
  917  history > myhistory.txt
  919  history | grep '>' > myhistory-write-commands.txt

In the command above grep is searching each line of output from the history command for a specific character (the redirect write operator >) and only putting matched lines into STDOUT which is then written to myhistory-write-commands.txt!

Take note that the redirect append operator was matched as a part of the grep search because it is made up of two characters that matched the grep search!