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
  • Activity: Listen to This Podcast That was created using AI from these materials. Transcript for the Podcast What are your thoughts? Did the AI do a good job representing the materials? Did you find any mistakes?
  • Go through This AI generated study guide, what do you think? Did it capture the week materials well? How did you do on the self quiz? Do you know all the vocab used?
  • Go through This AI generated briefing document, what do you think? Did it capture the week materials well? Was there anything it missed? Do you know all the vocab used?

Would you like to see some more classes? Click here