Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Terminal Awareness

Terminal Awareness

Just a general talk on being aware of how to work in the terminal, some basic scripting knowledge, and some tips, tricks and tools I picked up in about a year and a half of working nearly exclusively in a terminal.

No notes in this copy, which may make it a bit tough to follow

Ben Nicholas

March 26, 2014
Tweet

More Decks by Ben Nicholas

Other Decks in Programming

Transcript

  1. Shell Anatomy 101 • time php test.php 2>&1 | grep

    $NEEDLE > results.txt Shell Builtin Executables Arguments Redirection Pipe Environment Variable output
  2. Shell Anatomy 101 • time php test.php 2>&1 | grep

    $NEEDLE > results.txt Shell Builtin Executables Arguments Redirection Pipe Environment Variable output
  3. cat • Puts the contents of a file onto stdout

    • $ cat “hello.txt”
 Hello, world
  4. head/tail • Puts the beginning or end of a file

    on stdout • great for dealing with logs, especially with -f • $ tail -f /var/log/system.log
 Hello, world
  5. ps • list information about processes • $ ps axu

    | grep grep
 bnicholas 4521 0.0 0.0 2453264 692 s000 S+ 10:26PM 0:00.00 grep grep
  6. kill/killall • send a signal to processes by pid or

    name • $ kill -SIGUSR1 2048 • $ killall perl
  7. sort • Takes lines from stdin and sorts them on

    stdout • $ cat file.txt | sort • $ cat numbers.txt | sort -n
  8. uniq • Removes duplicate lines from stdin to stdout •

    $ cat file.txt | sort | uniq • $ cat ~/history | sort | uniq -c | sort -n
  9. grep • Search for a regular expression • can be

    used on stdin or files • $ cat /var/log/product.log | grep -i “error”
  10. tr • “trim” text, replacing characters with others • $

    cat sentence.txt | tr ‘ ‘ ‘\n’
 My
 name
 is
 ben.
  11. sed • stream editor: a mini text editor • Similar

    to vim find+replace syntax, but so much more too • $ echo “hello world!” | sed -e “s/ w.*d/bn.u/“
 hello bn.u!
  12. find • A file finder with extra • $ find

    . -name “*.orig” -print - delete • $ find . -type f —mtime -1 -print
  13. awk • a small programming language for dealing with columns

    • ps aux | grep grep | awk ‘{print $2}’
 6845
  14. conditionals • if [ $VAR = “foo” ]
 then
 echo

    “bar”
 else
 echo “baz”
 fi
  15. Better conditionals • Use && and || when possible •

    cat a.txt | grep “hello” && echo “world”
  16. Key-based auth • More secure and convenient than passwords •

    ssh-copy-id <username>@<host> • Last time you’ll need to type a password • Also applies to git, scp, sftp, and others
  17. vim

  18. dsh