Grep, pipes, filters, top, redirection and append

Learning outcomes:

  • Demonstrate the use of grep to filter a text file
  • Use redirection (or append) in a command and explain what is happening
  • Show the use of head, tail and diff

Would you like to download my PowerPoint to follow along?

  • Grep
    • grep is a command to filter lines that contain specific text
    • Examples
      • cat /etc/passwd
      • cat /etc/passwd | grep Jane
      • cat /etc/passwd | grep Jane |wc -l
      • cat /etc/passwd | grep -v Jane
  • Redirect and append
    • Redirect >
    • Append >>
    • What's the difference? Redirect erases the file contents, append puts the results at the end of the file
  • Display file options
    • cat Used to display a file
    • Alternatives head, tail and od
      • head displays top (default 10) lines
      • tail displays end (defaults to 10) lines
      • od displays any file by showing hex code
  • File comparison
  • Tar
    • What is a tarball? It means tape archive
    • Why are the used? To archive files, so they can be easily moved around and worked with
    • How do you use one?
      tar -cvf ~/name.tar /home/user/directory
    • Gzip is also used to compress into a gzip instead of archive. To use add z to the options (-cvzf) also change the extension to .tar.gz or .tgz

Suggested Activities and Discussion Topics:

  • Follow along with me on This video on how to use tar

Would you like to see some more classes? Click here