Skip to content

Latest commit

 

History

History
88 lines (67 loc) · 2.6 KB

CommandLine.md

File metadata and controls

88 lines (67 loc) · 2.6 KB

Command Line Introduction

This can be done either with a local installation or remote connection over ssh.

Start with how to get help with a command:

  • man
  • apropos (man -k)

Show a little of how to operate the terminal:

  • history/up/tab/ctrl-R/!!/../~
  • clear/reset/less
  • cd/ls/pwd/mkdir/rm/rmdir/touch/vi (with a file browser open)

Show that day to day tasks can be done on the command line:

  • bc
  • date
  • cal
  • lynx/links/w3m
  • cowsay/fortune as fun extras

Show a few systems level utilities:

  • ssh
  • scp/sftp
  • top

Explain the inspirations for command line piping, "the UNIX philosophy", and introduce Jon Bentley's challenge.

Iteratively build an example of the text pipeline:

  1. dmesg/echo - text source
  2. cut
  3. sort
  4. uniq
  5. tr
  6. wc
  7. grep
  8. less/more
  9. head/tail

Show that the pipeline can begin and end with a file:

This probably should include an explanation of stderr vs stdout, but hasn’t yet.

  • cat
  • > and <

Bentley's challenge

curl -o shakespeare.txt http://www.gutenberg.org/files/100/100.txt

cat shakespeare.txt | tr -cs A-Za-z '\n' | tr A-Z a-z | sort | uniq -c | sort -rn | sed 1q

  1. Pipe works of Shakespeare
  2. Convert all non-alpha characters to newlines, then squeeze each string of repeated newlines into a single newline
  3. Transform upper to lowercase
  4. Sort by alpha
  5. Print only unique lines with a count of duplicates
  6. Reverse numeric sort
  7. Print only 1 line

Bigrams

cat shakespeare.txt | tr -cs A-Za-z '\n' | tr A-Z a-z | awk -- 'prev!="" { print prev,$0; } { prev=$0; }' | sort | uniq -c | sort -rn | sed 1q

Trigrams

cat shakespeare.txt | tr -cs A-Za-z '\n' | tr A-Z a-z | awk -- 'first!=""&&second!="" { print first,second,$0; } { first=second; second=$0; }' | sort | uniq -c | sort -rn | sed 1q

Demonstrate programmability of the shell:

  • seq
  • for/do/done
  • if/then/elif/fi
  • integration.sh

Demonstrate transforming unformatted data to something more readable:

This was a last minute hack and needs refinement.

seq 1 500 50000 | tr '\n' ' ' | xargs -n3 echo | column -t

  1. Generate 1-50000, every 500th
  2. Transform newline to space
  3. Echo three rows at a time
  4. Have column align columns

seq 1 500 50000 | tr '\n' ' ' | xargs -n4 echo | tr ' ' ',' | column -t -s,

  1. Generate 1-50000, every 500th
  2. Transform newline to space
  3. Echo four rows at a time
  4. Transform space to comma
  5. Have column break on comma and align columns