Unix shell talk - RIT SSE

380 views

Published on

Tech Talk given at the Rochester Institute of Technology's Society of Software Engineers about basic unix shell usage and productivity tips.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
380
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Unix shell talk - RIT SSE

  1. 1. Text shells Matt Mokary and important productivity tips
  2. 2. TERMINAL-ogy ● Terminal window terminal window
  3. 3. TERMINAL-ogy ● Terminal window ● Terminal emulator terminal emulator terminal window
  4. 4. TERMINAL-ogy ● Terminal window ● Terminal emulator terminal emulator terminal window
  5. 5. TERMINAL-ogy ● Terminal window ● Terminal emulator ● Shell terminal emulator shell terminal window
  6. 6. Modern Shells ● C Shell (csh) ● Bourne Again Shell (bash) ● Korn Shell (ksh) ● Z Shell (zsh)
  7. 7. Modern Shells ● C Shell (csh) ● Bourne Again Shell (bash) ● Korn Shell (ksh) ● Z Shell (zsh)
  8. 8. Basic usage <program name> <program flags> [ arg1, arg2, … ] $ ls
  9. 9. Basic usage <program name> <program flags> [ arg1, arg2, … ] $ ls Applications Documents Library Desktop Downloads Music $
  10. 10. Basic usage <program name> <program flags> [ arg1, arg2, … ] $ ls -a
  11. 11. <program name> <program flags> [ arg1, arg2, … ] $ ls -a drwxr-xr-x 3 mattmokary staff 102 Feb 24 12:56 Applications drwx------+ 5 mattmokary staff 170 Mar 20 17:06 Desktop drwx------+ 11 mattmokary staff 374 Mar 20 12:03 Documents drwx------+ 56 mattmokary staff 1904 Mar 20 14:54 Downloads drwx------@ 49 mattmokary staff 1666 Feb 12 15:42 Library drwx------+ 5 mattmokary staff 170 Feb 20 00:12 Music $ Basic usage
  12. 12. <program name> <program flags> [ arg1, arg2, … ] $ grep -n TODO MyProject.java Basic usage
  13. 13. Basic usage <program name> <program flags> [ arg1, arg2, … ] $ grep -n TODO MyProject.java 23: // TODO is there an off-by-one error here? 131: // TODO document this function 340: // TODO make this more efficient $
  14. 14. <program name> <program flags> [ arg1, arg2, … ] $ gcc -o HelloWorld hello_world.c Basic usage
  15. 15. <program name> <program flags> [ arg1, arg2, … ] $ gcc -o HelloWorld hello_world.c $ Basic usage
  16. 16. <program name> <program flags> [ arg1, arg2, … ] $ gcc -o HelloWorld hello_world.c $ ls HelloWorld hello_world.c hello_world.o $ Basic usage
  17. 17. Streams
  18. 18. Streams ● Standard Input (stdin)
  19. 19. Streams ● Standard Input (stdin) ● Standard Output (stdout)
  20. 20. Streams ● Standard Input (stdin) ● Standard Output (stdout) ● Standard Error (stderr)
  21. 21. Streams $ cat test.txt
  22. 22. Streams $ cat test.txt This is a test file. It has several lines, none of which are very helpful. This is the last line of the file. $
  23. 23. Stream Redirection ● >
  24. 24. Stream Redirection ● > $ grep TODO MyProject.java
  25. 25. Stream Redirection ● > $ grep TODO MyProject.java // TODO make this better // TODO delete these $
  26. 26. Stream Redirection ● > $ grep TODO MyProject.java > todo.txt
  27. 27. Stream Redirection ● > $ grep TODO MyProject.java > todo.txt $
  28. 28. Stream Redirection ● > $ grep TODO MyProject.java > todo.txt $ ls MyProject.java todo.txt $
  29. 29. Stream Redirection ● > $ grep TODO MyProject.java > todo.txt $ ls MyProject.java todo.txt $ cat todo.txt // TODO make this better // TODO delete these $
  30. 30. Stream Redirection ● > >> $ grep TODO MyProject.java > todo.txt $ ls MyProject.java todo.txt $ cat todo.txt // TODO make this better // TODO delete these $
  31. 31. Stream Redirection ● > >> ● <
  32. 32. Stream Redirection ● > >> ● < $ grep TODO MyProject.java // TODO make this better // TODO delete these $
  33. 33. Stream Redirection ● > >> ● < $ grep TODO < MyProject.java // TODO make this better // TODO delete these $
  34. 34. Stream Redirection ● > >> ● < ● |
  35. 35. Stream Redirection ● > >> ● < ● | $ grep TODO MyProject.java > todo.txt $ wc -l todo.txt 2 $ rm todo.txt
  36. 36. Stream Redirection ● > >> ● < ● | $ grep TODO MyProject.java | wc -l
  37. 37. Stream Redirection ● > >> ● < ● | $ grep TODO MyProject.java | wc -l 2
  38. 38. Stream Redirection ● > >> ● < ● | $ grep TODO MyProject.java | wc -l 2 $ ruby get_hockey_tweets.rb | grep -in sedin | grep -i henrik | wc -l 173 $
  39. 39. Stream Redirection ● > redirect stdout to file stream >> append stdout to file stream ● < redirect file stream to stdin ● | redirect stdout and stderr to stdin
  40. 40. Stream Redirection ● stdin (channel 0) ● stdout (channel 1) ● stderr (channel 2)
  41. 41. Stream Redirection $ ./sqrt -1 2> errors.txt No real solution. $
  42. 42. Stream Redirection $ ./sqrt -1 2> errors.txt No real solution. $ cat errors.txt Argument is less than zero. $
  43. 43. Stream Redirection $ ./sqrt -1 2> errors.txt 1> /dev/null $ cat errors.txt Argument is less than zero. $
  44. 44. Stream Redirection $ ./postfix-solver 3 4 + 2>&1 > /dev/null | grep syntax > syntax-errors.txt
  45. 45. Stream Redirection $ ./postfix-solver 3 4 + 2>&1 > /dev/null | grep syntax > syntax-errors.txt
  46. 46. Stream Redirection $ ./postfix-solver 3 4 + 2>&1 > /dev/null | grep syntax > syntax-errors.txt
  47. 47. Stream Redirection $ ./postfix-solver 3 4 + 2>&1 > /dev/null | grep syntax > syntax-errors.txt
  48. 48. Stream Redirection $ ./postfix-solver 3 4 + 2>&1 > /dev/null | grep syntax > syntax-errors.txt
  49. 49. Stream Redirection $ ./postfix-solver 3 4 + 2>&1 > /dev/null | grep syntax > syntax-errors.txt
  50. 50. Stream Redirection $ ./postfix-solver 3 4 + 2>&1 > /dev/null | grep syntax > syntax-errors.txt $
  51. 51. Stream Redirection $ ./postfix-solver 3 4 + 2>&1 > /dev/null | grep syntax > syntax-errors.txt $ ls postfix-solver syntax-errors.txt $
  52. 52. Stream Redirection $ ./postfix-solver 3 4 + 2>&1 > /dev/null | grep syntax > syntax-errors.txt $ ls postfix-solver syntax-errors.txt $ cat syntax-errors.txt $
  53. 53. Stream Redirection ● stdin 0 ● stdout 1 ● stderr 2 ● 2> redirect stderr to file stream ● 2>&1 redirect stderr to current stdout etc.
  54. 54. Every SE Ever:
  55. 55. Every SE Ever: “I have no idea why this isn’t working.”
  56. 56. Every SE Ever: “I have no idea why this isn’t working.” “I have no idea why this is working.”
  57. 57. Every SE Ever: “I have no idea why this isn’t working.” “I have no idea why this is working.” “How do I get out of vim?”
  58. 58. vim Modes ● Normal
  59. 59. vim Modes ● Normal o insert a new line beneath the cursor, move to it, and enter insert mode $ move to the end of the line and remain in normal mode i enter insert mode at the cursor’s current position I move to the beginning of the line and enter insert mode dd cut the current line
  60. 60. vim Modes ● Normal ● Insert
  61. 61. vim Modes ● Normal ● Insert ● Command
  62. 62. vim Modes ● Normal ● Insert ● Command :w write the buffer to the disk :q quit vim; will stop you if the file has changed since the last write :q! quit vim and discard changes since last write :wq write the buffer and quit vim :x same as :wq :<some number> move the cursor to line <some number>
  63. 63. Typical vim Workflow
  64. 64. Typical vim Workflow $ vim some-file.txt
  65. 65. Typical vim Workflow $ vim some-file.txt until you’ve made all the desired changes: navigate through the file in normal mode
  66. 66. Typical vim Workflow $ vim some-file.txt until you’ve made all the desired changes: navigate through the file in normal mode bounce between normal and insert until part is fixed
  67. 67. Typical vim Workflow $ vim some-file.txt until you’ve made all the desired changes: navigate through the file in normal mode bounce between normal and insert until part is fixed enter normal mode and write the file with “:w”
  68. 68. Typical vim Workflow $ vim some-file.txt until you’ve made all the desired changes: navigate through the file in normal mode bounce between normal and insert until part is fixed enter normal mode and write the file with “:w” enter normal mode
  69. 69. Typical vim Workflow $ vim some-file.txt until you’ve made all the desired changes: navigate through the file in normal mode bounce between normal and insert until part is fixed enter normal mode and write the file with “:w” enter normal mode write the file and quit vim with “:wq” or “:x”
  70. 70. vim Visual Mode
  71. 71. vim Visual Mode x cut the highlighted text and save it to vim’s clipboard y copy the highlighted text and save it to vim’s clipboard p (in normal mode) paste the text in vim’s clipboard into the buffer after the cursor P (in normal mode) paste the text in vim’s clipboard into the buffer before the cursor
  72. 72. tmux
  73. 73. tmux $ Shell
  74. 74. tmux $ tmux new -s Crypto $ Shell tmux session “Crypto”
  75. 75. tmux $ tmux new -s Crypto $ tmux ls Crypto: 1 windows … (attached) $ Shell tmux session “Crypto”
  76. 76. tmux $ tmux new -s Crypto $ tmux ls Crypto: 1 windows … (attached) $ tmux detach $ Shell tmux session “Crypto”
  77. 77. tmux $ tmux new -s Crypto $ tmux ls Crypto: 1 windows … (attached) $ tmux detach $ tmux new -s Grading $ Shell tmux session “Crypto” tmux session “Grading”
  78. 78. tmux $ tmux new -s Crypto $ tmux ls Crypto: 1 windows … (attached) $ tmux detach $ tmux new -s Grading $ tmux kill-session -t Crypto $ Shell tmux session “Grading”
  79. 79. tmux $ tmux new -s Crypto $ tmux ls Crypto: 1 windows … (attached) $ tmux detach $ tmux new -s Grading $ tmux kill-session -t Crypto $ tmux detach $ Shell tmux session “Grading”
  80. 80. tmux Session
  81. 81. tmux Session CTRL+b % vertical split
  82. 82. tmux Session CTRL+b % vertical split CTRL+b “ horizontal split
  83. 83. tmux Session CTRL+b % vertical split CTRL+b “ horizontal split CTRL+b x y kill pane
  84. 84. tmux Session CTRL+b % vertical split CTRL+b “ horizontal split CTRL+b x y kill pane CTRL+b arrows navigate panes
  85. 85. My Personal Setup
  86. 86. Thanks!

×