Teacher's Handbook

Teacher's Handbook

Open in ChatGPT
Ask ChatGPT about this page
Open in Claude
Ask Claude about this page

Terminal & Shell

The idea at this point is to make them comfortable with working in the terminal. When programming foundations start, it will pay off.

Base material:

CS17_Terminal_Shell_Lesson_Plan_No_Programming.pdf

Session 1

  • File System
    • Draw on board the tree (root > folder > more folders etc.)
    • They have been creating this through UI (mouse till now)
  • Terminal vs Shell
  • Commands:
    • pwd
    • ls
    • cd
      • explain:
        • cd .. and cd ~ (~ is home, not root)
    • mkdir
      • when they try to make multiple directories using one command each, show them mkdir d1 d2 d3 (faster than UI, they can start to see the value!)
      • Also, what if "d1 d2" should be file name, need to wrap in quotes.
    • touch
    • cat
    • echo
      • Then combine echo with >:
        • echo "Hello World" > file.txt
        • >> for append
    • cp
    • mv : show both move and rename with this
    • rm
    • rmdir

Practice in between, ask them to create this structure using terminal commands they just learned:

Frappeverse
-------> photos
--------------> mumbai
----------------------> all.txt
-------> blog
-------------> <your-name>.txt

Session 2 <Practice with TAs>

Make them run commands on their computers (by Shivam)

Session 3

  • history
  • Tab Completions and Up Arrow Key for navigating through history
  • grep (the very basics) (take an example where the file contains multiple lines and occurrences of the word)
grep apple fruits.txt
  • Command anatomy:
    • e.g. cp hello.txt backup/
    • command argument argument
  • Flags
    • e.g. ls -l ls -a (good time to make them see the difference that just ls will not show hidden (i.e. starting with a .) files and folders.
  • wc (stands for word count):
wc fruits.txt # 5 14 65 story.txt
wc -l fruits.txt # 5 story.txt

In the above, 5 is the number of lines, 14 is the number words, and 65 is the number of bytes in the given file(s). If -l option is given, only number of lines are printed.

  • man (manual pages) and --help
    • show for wc etc.
    • they should be able to at least skim
  • Wildcards
    • e.g. list all jpg images in a file, all files starting with the letter p
      • ls *.jpg and ls p*
    • then expand to show how the wildcards are not just in ls but can be used to carry out copy, move etc.
      • move all jpg images to images/ folder etc.
      • e.g. math_1.txt math_2.txt math_3.txt cs_1.txt cs_2.txt cs_3.txt move math notes to math/ folder and cs notes to cs/ folder.

Session 4 <Practice with TAs>

Practice with TAs.

Session 5

  • head and tail
    • head / tail by default 10 lines
    • head -n 5 first 5 lines, with tail last 5 lines.
    • show examples
  • (important to understand) redirection
    • analogy of redirecting someone from where he was actually "directed" towards
    • it was going to come on screen, but we asked the shell program to redirect it to some file instead
    • Show if "ls >> list.txt", list.txt will get auto created if not exists, don't have to touch.
  • (important to understand) pipe
    • Again analogy to actual pipe connecting different chambers (e.g. water treatment plan) where each chamber does some mixing and the contents are forwarded to the next output pipe
    • Take examples and make them practice:
$ ls | grep "apple" # list of files/dir that have apple in their name
$ history | tail -n 50 | grep "mkdir" > commands.txt

Good opportunity to give textual questions and see if they can breakdown the problem and chain the commands to get it done.

Last updated 3 weeks ago